如何修复404错误以关注struts 2框架中的Action类(控制器)和struts.xml

时间:2014-04-23 16:59:26

标签: java struts2

我需要你的帮助。 我有struts.xml和文件Action类的问题。 几天前,我的项目很好但是今天当我运行我的项目时,在网络浏览器上出现404错误如下:

HTTP状态404 - /Food/Home.jsp 类型状态报告 消息/Food/Home.jsp description请求的资源(/Food/Home.jsp)不可用。 Apache Tomcat / 6.0.16

在Eclipse的控制台中:   **

> Unable to load configuration. - action -
> file:/E:/Java/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/Food/WEB-INF/classes/struts.xml:7:75
>   at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:431)
>   at
> org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:190)
>   at
> org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
>   at
> org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
>   at
> org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
>   at
> org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3709)
>   at
> org.apache.catalina.core.StandardContext.start(StandardContext.java:4356)
>   at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
>   at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
>   at
> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
>   at
> org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
>   at
> org.apache.catalina.core.StandardService.start(StandardService.java:516)
>   at
> org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
>   at org.apache.catalina.startup.Catalina.start(Catalina.java:578)    at
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at
> sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)   at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)   at
> java.lang.reflect.Method.invoke(Unknown Source)   at
> org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)   at
> org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413) Caused
> by: Unable to load configuration. - action -
> file:/E:/Java/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/Food/WEB-INF/classes/struts.xml:7:75
>   at
> com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
>   at
> org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:374)   at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:418)
>   ... 19 more Caused by: Action class [controller_user.Login] not found
> - action - file:/E:/Java/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/Food/WEB-INF/classes/struts.xml:7:75
>   at
> com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:409)
>   at
> com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:354)
>   at
> com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:468)
>   at
> com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:264)
>   at
> org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111)
>   at
> com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:193)
>   at
> com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
>   ... 21 more

**
You should look at the error "**Caused by: Action class [controller_user.Login] not found - action - file:/E:/Java/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/Food/WEB-INF/classes/struts.xml:7:75**".This is cause for Can not load my Home page or any else page

如果我在struts.xml中清除这些行

         <action name="login" class="controller_user.Login" method="loginAction">
        <result name="success">/User/Registration.jsp</result>
        <result name="failed">/User/LoginFailed.jsp</result>
    </action>

=&GT;运行我的项目是好的

我不知道如何解决这个问题.Plz帮帮我

1 个答案:

答案 0 :(得分:0)

您需要将完全限定的类名放在class属性中。 controller_user是您的完整非标准包名吗?它应该是这样的:

<action name = "login" 
       class = "com.foo.bar.controller.user.Login" 
      method = "loginAction" >