Struts2注解错误之There is no Action mapped for namespace /

我用最新版本的Struts2.3.4做注解操作的时候,一直出现这个问题。花了近两个小时才解决,错误原因让人啼笑皆非……

[plain] view plaincopy

  1. There is no Action mapped for namespace [/] and action name [test] associated with context path [/test]. - [unknown location]
  2. at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
  3. at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
  4. at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
  5. at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
  6. at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:501)
  7. at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
  8. at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
  9. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
  10. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  11. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
  12. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
  13. at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  14. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
  15. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
  16. at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
  17. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  18. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  19. at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
  20. at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
  21. at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1805)
  22. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
  23. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
  24. at java.lang.Thread.run(Thread.java:722)

web.xml

[html] view
plain
copy

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  4. http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  5. <display-name>test-struts</display-name>
  6. <filter>
  7. <filter-name>struts2</filter-name>
  8. <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  9. </filter>
  10. <filter-mapping>
  11. <filter-name>struts2</filter-name>
  12. <url-pattern>*.action</url-pattern>
  13. </filter-mapping>
  14. <welcome-file-list>
  15. <welcome-file>index.jsp</welcome-file>
  16. </welcome-file-list>
  17. </web-app>

TestAction.java

[java] view
plain
copy

  1. package com.test.Action;
  2. import org.apache.struts2.convention.annotation.Action;
  3. import org.apache.struts2.convention.annotation.Result;
  4. import org.apache.struts2.convention.annotation.Results;
  5. import com.opensymphony.xwork2.ActionSupport;
  6. @Results(value = { @Result(name = "success", location = "/result.jsp") })
  7. public class TestAction extends ActionSupport {
  8. private String name;
  9. /**
  10. *
  11. */
  12. private static final long serialVersionUID = 1L;
  13. @Action("test")
  14. public String test() {
  15. name = "qqqqqqq";
  16. return SUCCESS;
  17. }
  18. public String getName() {
  19. return name;
  20. }
  21. public void setName(String name) {
  22. this.name = name;
  23. }
  24. }

目录结构:

乍一看,是没有任何问题的!可是只要一运行就报错!在百思不得其解后,突然发现我这个包名建的有点特别,问题就出在这里!将Action换成action就可以了,以下是Struts2的原文文档:

First the Convention plugin finds packages named strutsstruts2action or actions.
Any packages that match those names are considered the root packages for the Convention plugin. Next, the plugin looks at all of the classes in those packages as well as sub-packages and determines if the classes implementcom.opensymphony.xwork2.Action or
if their name ends with Action (i.e. FooAction).

注意我标红的内容,也就是说,如果要用Struts2的注解,你还非得将action处理类放在strutsstruts2action, actions包或者其子包中。以前总是习惯性的将所有的action处理类放在com.xxx.action下,以为仅仅是习惯而已,没曾想Struts2还就是这么规定的。

碰到了同样的问题,以前确实不知道基于注解的 struts 配置 需要将action类 放在 名字为 action 的package下。

所用JAR包:

commons-beanutils-1.7.0.jar

commons-codec-1.3.jar

commons-collections-3.2.jar

commons-digester-1.5.jar

commons-fileupload-1.2.1.jar

commons-io-1.4.jar

commons-lang-2.3.jar

commons-logging-1.1.1.jar

commons-validator-1.3.1.jar

ezmorph-1.0.4.jar

freemarker-2.3.8.jar

jsf-api.jar

jsf-impl.jar

jstl-1.2.jar

ognl-2.6.11.jar

struts2-convention-plugin-2.2.1.1.jar

struts2-core-2.2.1.1.jar

xml-apis-1.0.b2.jar

xwork-core-2.2.1.1.jar

 

 

 

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

原文地址:https://www.cnblogs.com/skinchqqhah/p/10350255.html

时间: 2024-07-29 19:30:26

Struts2注解错误之There is no Action mapped for namespace /的相关文章

Struts2错误:There is no Action mapped for namespace... 解决方法

今天在使用 Struts2.1 做注解操作的时候,一直出现这个问题.花了半天时间才解决,错误原因真是让人蛋疼! 错误提示: 项目结构: 使用注解的位置: package com.service; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.convention.annotation.Action; impor

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

最近更新struts版本发现,无论怎么访问就是无法映射到指定的配置文件,最后发现原来是访问控制的原因. struts2.3之后为了访问安全,增加了请求方法拦截,这样会造成使用通配符访问时无法找到映射对象的错误提示: There is no Action mapped for namespace [/] and action name [m_hi] associated with context path []. 解决方式: 1 如果你的引用包struts2-core是2.3以上版本需要更新str

关于Struts2中的错误:例如There is no Action mapped for namespace / and action name product-input.

            在配置struts.xml 文件时,会出现    There is no Action mapped for namespace / and action name ....    意思是没有product-input的映射文件或者是命名空间       出现这样的错误的原因后:     做如下检查:           1: 把struts.xml中的namespace="/"改成namespace=""或者去除,使用默认的命名空间. 2:

错误There is no Action mapped for namespace / and action name—Struts2

Struts2出现错误,总是提示"There is no Action mapped for namespace / and action name"的错误. 错误代码如下: 09:36:13,515 WARN [Dispatcher] Could not find action or result There is no Action mapped for namespace [/] and action name [css] associated with context path

struts2中错误There is no Action mapped for namespace [/] and action name [] associated with context path

1 There is no Action mapped for namespace [/] and action name [] associated with context path [/Struts2_0300_Action2]. - [unknown location] 2 at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185) 3 at org.apache.struts2.i

Struts2中There is no Action mapped for namespace错误解决方法

1.我的原有配置 jsp表单提交路径 <form class="layui-form" id="form" action="${ctx }/membersLogin/membersLoginAction!membersLogin.action"> ............ </form> struts2拦截配置 <package name="default" extends="strut

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [Action!Method]错误解决

按照书本上的Struts2的例子,运行会出现错误: HTTP Status 404 - There is no Action mapped for namespace [/] and action name [sayHelloAction!sayStruts2] ... 貌似在struts.xml中配置action的method不会出错,而直接在jsp中写“Action!Method.action”就会报错. 搜索许久没有发现解决办法,后来发现第二种写法叫做“DMI”,会产生安全隐患,在stru

Struts2中关于&quot;There is no Action mapped for namespace / and action name&quot;的总结

今天在调试一个基础的Struts2框架小程序.总是提示"There is no Action mapped for namespace / and action name"的错误.上网查询后发现这是一个初学者经常碰到的问题,导致错误的原因主要有两种.总结如下: 一.struts.xml文件错误.这种错误又分为以下几种:1,struts.xml文件名错误.一定要注意拼写问 题:2,struts.xml文件放置路径错误.一定要将此文件放置在src目录下.编译成功后,要确认是否编译到clas

struts2 : There is no Action mapped for namespace / and action name

2015.07.13 晚 学习搭建SSI 框架,用到struts2 ,启动后访问指定login.action报错 There is no Action mapped for namespace / and action name 查找原因,struts.xml 没有被找到. 解决方法 1 : 在web.xml中指定struts.xml 的位置 解决方法 2 : 将struts.xml 放在src根目录下,web.xml中不需配置struts.xml的地址. 总结 ,对框架各配置文件之间作用不了解