u010791853
Daniel Mao
2015-08-03 03:25
采纳率: 21.1%
浏览 3.6k

struts报Unable to load configuration. - action

  1. 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"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <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>
  1. struts.xml文件内容
 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
    <package name="default" namespace="/" extends="struts-default">
        <action name="Login" class="lee.Login">  
        <result name="error">/error.jsp</result>  
    </action> 
    </package>
</struts>

  1. action类的内容
 package lee;

public class Login {
    private String username;
    private String password;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    // 处理用户请求的execute方法
    public String execute() throws Exception {
        // 当用户请求参数的username等于scott,密码请求参数为tiger时,返回success字符串
        // 否则返回error字符串
        if (getUsername().equals("scott") && getPassword().equals("tiger")) {
            return "success";
        } else {
            return "error";
        }
    }
}

错误信息:
11:26:40.635 [localhost-startStop-1] ERROR org.apache.struts2.dispatcher.Dispatcher - Dispatcher initialization failed
com.opensymphony.xwork2.config.ConfigurationException: Unable to load configuration.
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70) ~[xwork-core-2.3.24.jar:2.3.24]
at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:967) ~[struts2-core-2.3.24.jar:2.3.24]
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:435) ~[struts2-core-2.3.24.jar:2.3.24]
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:479) [struts2-core-2.3.24.jar:2.3.24]
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74) [struts2-core-2.3.24.jar:2.3.24]
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57) [struts2-core-2.3.24.jar:2.3.24]
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279) [catalina.jar:7.0.63]
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260) [catalina.jar:7.0.63]
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:105) [catalina.jar:7.0.63]
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4855) [catalina.jar:7.0.63]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5549) [catalina.jar:7.0.63]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.63]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574) [catalina.jar:7.0.63]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564) [catalina.jar:7.0.63]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) [?:1.7.0_80]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [?:1.7.0_80]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [?:1.7.0_80]
at java.lang.Thread.run(Thread.java:745) [?:1.7.0_80]
Caused by: com.opensymphony.xwork2.config.ConfigurationException: Action class [lee.Login] not found
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:486) ~[xwork-core-2.3.24.jar:2.3.24]
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:429) ~[xwork-core-2.3.24.jar:2.3.24]
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:556) ~[xwork-core-2.3.24.jar:2.3.24]
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:295) ~[xwork-core-2.3.24.jar:2.3.24]
at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112) ~[struts2-core-2.3.24.jar:2.3.24]
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:264) ~[xwork-core-2.3.24.jar:2.3.24]
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67) ~[xwork-core-2.3.24.jar:2.3.24]
... 17 more
八月 03, 2015 11:26:40 上午 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
Unable to load configuration. - action - file:/D:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/struts_001/WEB-INF/classes/struts.xml:8:42
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.(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4855)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5549)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: Unable to load configuration. - action - file:/D:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/struts_001/WEB-INF/classes/struts.xml:8:42
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)
... 14 more
Caused by: Action class [lee.Login] not found - action - file:/D:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/struts_001/WEB-INF/classes/struts.xml:8:42
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)
... 17 more

八月 03, 2015 11:26:40 上午 org.apache.catalina.core.StandardContext startInternal
严重: One or more Filters failed to start. Full details will be found in the appropriate container log file
八月 03, 2015 11:26:40 上午 org.apache.catalina.core.StandardContext startInternal
严重: Context [/struts_001] startup failed due to previous errors
八月 03, 2015 11:26:40 上午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-apr-8080"]
八月 03, 2015 11:26:40 上午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-apr-8009"]
八月 03, 2015 11:26:40 上午 org.apache.catalina.startup.Catalina start
信息: Server startup in 2523 ms

只要去掉struts.xml文件中的class="lee.Login"就不报错了

struts的jar文件
图片说明

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • niyehunwu

    Caused by: Unable to load configuration. - action - file:/D:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/struts_001/WEB-INF/classes/struts.xml:8:42
    出问题的地方已经说了。只要去掉struts.xml文件中的class="lee.Login"就不报错了,那问题肯定就出在这个地方了,可以把struts.xml代码贴出来吗,还有就是看一下编译文件里jar包有没有重复的。

    点赞 评论
  • a4562116
    a4562116 2015-08-03 05:17

    Login需要继承struts中的actionsurport这个类,具体名字可能有误,如果错了可以百度

    点赞 评论

相关推荐