首页 > 代码库 > There is no Action mapped for namespace [/] and action name [xx] associated with context path...

There is no Action mapped for namespace [/] and action name [xx] associated with context path...

好久没用Struts了,今天练了一个简单的应用,出现了一些意外的问题,由于这种原因一直报404

首先我的目录结构是这样子滴

技术分享

 

web.xml中是这样配置的

<web-app>
<display-name>Archetype Created Web Application</display-name>

<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>

<welcome-file-list>
<welcome-file>/WEB-INF/welcome.jsp</welcome-file>
</welcome-file-list>
</web-app>

很简单,struts拦截所有,外加一个欢迎页

struts.xml是这样的

<struts>
<constant name="struts.devMode" value="http://www.mamicode.com/true"></constant>
<constant name="struts.i18n.encoding" value="http://www.mamicode.com/UTF-8"></constant>
<constant name="struts.locale" value="http://www.mamicode.com/zh_CN"></constant>

<package name="default" namespace="/WEB-INF/pages" extends="struts-default">
<action name="index">
<result>login.jsp</result>
</action>

<action name="login" class="com.tjjy.struts.Login">
<result name="SUCCESS">ok.jsp</result>
</action>
</package>

</struts>

这里只有一个命名空间

欢迎页配置更简单

<body>
欢迎!!!!!!!!!!!!!!!
<a href = "http://www.mamicode.com/index.action">点我</a>
</body>

思路是:启动服务器,首先进入欢迎页然后进去登陆页,然后登陆成功

但运行时却是

There is no Action mapped for namespace [/] and action name [] associated with context path [/StrutsTest]. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:536)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:744)

 说我的该命名空间下找不到我要请求的action

一开始以为struts拦截器有问题分别进行修改

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

 <package name="default" namespace="/WEB-INF/pages" extends="struts-default"> 
<action name="index.action"> 
<result>login.jsp</result> 
</action> 

结果依然和上面一样,很明显问题不在这里,但明明报错是说找不到action,那就一定是url的问题,后经过一段时间,进行各种url写法的尝试,都失败了,换个角度是不是在欢迎页就开始出问题了

这下发现一个很愚蠢很低级的问题就是,欢迎页的路径错误,改为:

<welcome-file-list>
<welcome-file>/WEB-INF/welcome.jsp</welcome-file>
</welcome-file-list>

成功,又试了上面的更改过的url方式,都是没问题的,知识不能一味追求新的,要温故而知新,时间久不用竟然连基础的都忘了

 

There is no Action mapped for namespace [/] and action name [xx] associated with context path...