错误:无法加载配置。 - action,引起:在eclipse上运行Strache 2时,没有找到Action类

时间:2015-07-03 08:07:20

标签: java eclipse jsp tomcat struts2

我遵循了Javabrains教程,当在Eclipse上运行Tomcat上的Struts 2应用程序时,它会出现以下错误:

  

HTTP状态404 - / Struts2Starter /
      description-请求的资源不可用。

Jul 3, 2015 1:10:11 PM org.apache.struts2.dispatcher.Dispatcher error
SEVERE: Dispatcher initialization failed
Unable to load configuration. - action - file:/C:/Software_Installation/Apache/apache-tomcat-7.0.62/wtpwebapps/Struts2Starter/WEB-INF/classes/struts.xml:10:83
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
    at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:967)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:435)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:479)
    at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57)
    at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4854)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5546)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
Caused by: Action class [org.koushik.javabrains.action.TutorialAction] not found - action - file:/C:/Software_Installation/Apache/apache-tomcat-7.0.62/wtpwebapps/Struts2Starter/WEB-INF/classes/struts.xml:10:83
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:486)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:429)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:556)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:295)
    at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:264)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
    ... 18 more
Jul 3, 2015 1:10:11 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter struts2
Unable to load configuration. - action - file:/C:/Software_Installation/Apache/apache-tomcat-7.0.62/wtpwebapps/Struts2Starter/WEB-INF/classes/struts.xml:10:83
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:493)
    at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57)
    at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4854)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5546)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
Caused by: Unable to load configuration. - action - file:/C:/Software_Installation/Apache/apache-tomcat-7.0.62/wtpwebapps/Struts2Starter/WEB-INF/classes/struts.xml:10:83
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
    at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:967)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:435)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:479)
    ... 15 more

struts.xml中

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC 
    "-//apache software foundation//DTD StrutsConfiguration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

    <package name="default" namespace="/tutorials" extends="struts-default">
        <action name="getTutorial" class="org.koushik.javabrains.action.TutorialAction">
            <result name="success">/success.jsp</result>
            <result name="failure">/error.jsp</result>
        </action>

    </package>


</struts>

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>Struts2Starter</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
         <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

TutorialAction.java

package org.koushik.javabrains.action;

public class TutorialAction {

    public String execute(){
        System.out.println("Hello from execute");
        return "failure" ;
    }
}

我创建了success.jsp,error.jsp&amp; index.jsp文件也是如此。我正在使用eclipse-indigo&amp; Apache tomcat 7.0.62。当我在Tomcat服务器上运行项目时,它在控制台上显示此错误消息并显示HTTP状态404 - / Struts2Starter描述所请求的资源不可用。名为Apache Tomcat的新选项卡上的错误消息。

1 个答案:

答案 0 :(得分:1)

将.jar文件复制到 WebContent / WEB-INF / lib 文件夹中,根据struts库教程提供的部署程序集定义在部署应用程序时可能无法正常工作。它对我有用。