访问路径为:http://127.0.0.1:8080/TEST2/user!add?user.name=a&user.age=1报错:
Struts Problem ReportStruts has detected an unhandled exception:Messages:
There is no Action mapped for namespace [/] and action name [user!add] associated with context path [/TEST2].
StacktracesThere is no Action mapped for namespace [/] and action name [user!add] associated with context path [/TEST2]. - [unknown location]
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:536)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
    org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
    org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1760)
    java.lang.Thread.run(Thread.java:619)
actionpackage com.strut2.action.user;import com.opensymphony.xwork2.ActionSupport;public class UserAction extends ActionSupport {
private String name;
private int age;
public String add(){
System.out.println("name="+name);
System.out.println("age="+age);
return SUCCESS;
}
public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public int getAge() {
return age;
} public void setAge(int age) {
this.age = age;
}
public String add(){
System.out.println("name="+name);
System.out.println("age="+age);
return SUCCESS;
}



}
struts.xml
<struts>    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">

     <action name="user" class="com.strut2.action.user.UserAction" >
           <result>
               /ActionAttrubute.jsp
           </result>
     </action>
        
    </package>
</struts>
求解答struts2

解决方案 »

  1.   

    http://127.0.0.1:8080/TEST2/user!add.action?user.name=a&user.age=1
      

  2.   

    你这个问题,初学者经常遇到,网上也有好多这个问题的答案,直接在google里面搜“There is no Action mapped for namespace [/] and action name [user!add] associated with context path”就能找到。
    楼上说的那种情况就得看你的web.xml里面是怎么配置的。
    仔细点儿
      

  3.   

    不好意思 贴代码的时候贴错了  底下的add()方法是没有的
      

  4.   


    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">    <display-name>Struts Blank</display-name>
    <welcome-file-list>
            <welcome-file>index.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>
      

  5.   


    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">    <display-name>Struts Blank</display-name>
    <welcome-file-list>
            <welcome-file>index.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>

    struts.xml贴出来。这个错误是没有配置Action
      

  6.   

    <action name="user" class="com.strut2.action.user.UserAction" method="add" >
                   <result>
                       /ActionAttrubute.jsp
                   </result>
                 </action>
      

  7.   

    <constant name="struts.enable.DynamicMethodInvocation" value="true" /> 
    使用动态方法 也就是!