首页 新闻 会员 周边 捐助

Struts2.3.28no Action mapped for namespace [/] and action name [userAction!add] associated with cont

0
悬赏园豆:5 [待解决问题]
如图为项目结构:

web.xml配置如下:
<?xml version="1.0" encoding="UTF-8"?>
     id="WebApp_ID" version="3.0">
  <display-name>15.2</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>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

“实体类方法”如下:
package com.wgh;
 
import com.opensymphony.xwork2.ActionSupport;
 
public class UserAction extends ActionSupport{
    private String info;
 
    public String add() throws Exception{
        setInfo("添加用户信息");
        return "add";
    }
 
    public String update() throws Exception{
        setInfo("修改用户信息");
        return "update";
    }
    public String getInfo() {
        return info;
    }
 
    public void setInfo(String info) {
        this.info = info;
    }
 
 
}

struts.xml配置如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
 
<struts>
   <!--  <constant name="struts.action.extension" value="do" /> -->
    <constant name="struts.devMode" value="false" />
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
 
    <package name="user" namespace="/" extends="struts-default">
        <action name="userAction" class="com.wgh.UserAction">
            <result name="add">/WEB-INF/user_add.jsp</result>
            <result name="update">/WEB-INF/user_update.jsp</result>
        </action>
    </package>
 
</struts>

JSP页面如下:
user_add.jsp:
user_update.jsp:
index.jsp:

运行效果:
信息: Server startup in 1814 ms
三月 30, 2016 11:03:00 上午 org.apache.struts2.dispatcher.Dispatcher warn
警告: Could not find action or result: /15.2/userAction!add
There is no Action mapped for namespace [/] and action name [userAction!add] associated with context path [/15.2]. - [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:37)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:557)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    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:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

运行后点击超链接报错!

流月星的主页 流月星 | 初学一级 | 园豆:199
提问于:2016-03-30 11:23
< >
分享
所有回答(1)
0

把你的jsp页面中的链接贴出来

npe0 | 园豆:1502 (小虾三级) | 2016-04-01 15:11

还有package的name一般是default,另外看你jsp的命名方式,很像是用了通配符,

可参考:

<package name="default" namespace="" extends="struts-default">

<!--用户登录-->
<action name="userAction_*" class="com.ems.UserAction" method="{1}">
<result name="success">success.jsp</result>
<result name="failer">/login/login.jsp</result>
<result name="managerLoginSuccess">/manager3/index.jsp</result>
<result name="teacherLoginSuccess">/teacher/index.jsp</result>
<result name="studentLoginSuccess">/student/index.jsp</result>
</action>

</package>

支持(0) 反对(0) npe0 | 园豆:1502 (小虾三级) | 2016-04-01 15:17

@飞龙在天001: 我的链接如下:

<body>
<a href="userAction!add">添加用户</a>
<a href="userAction!update">修改用户</a>
</body>

支持(0) 反对(0) 流月星 | 园豆:199 (初学一级) | 2016-04-01 15:45

@流月星: 你把stucts.xml中的这句<constant name="struts.enable.DynamicMethodInvocation" value="false" />

改为:

<constant name="struts.enable.DynamicMethodInvocation" value="true" />

试试

支持(0) 反对(0) npe0 | 园豆:1502 (小虾三级) | 2016-04-13 15:47
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册