注册 登录
编程论坛 J2EE论坛

关于struts2 动态action 的问题

z511963074 发布于 2013-10-10 19:04, 2237 次点击
下面是我的struts2.xml的配置,有一个action :

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.

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

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

        <action name="first" class="FirstAction" >
            <result>
                /Hello.jsp
            </result>
            <result name="add">
                /add.jsp
            </result>
            <result name="update">
                /update.jsp
            </result>
        </action>

    </package>
   
</struts>

然后是我定义的action 类:
import com.opensymphony.xwork2.ActionSupport;
public class FirstAction extends ActionSupport {
        @Override
        public String execute() throws Exception {
             return SUCCESS;
        }
   
        public String update() throws Exception {
                return "update";
        }
   
        public String add() throws Exception {
             return "add";
        }

}

问题来了,我在地址栏敲入http://localhost:8080/struts_test_1.0/first 的时候能够正常打开Hello.jsp页面,但是我敲入http://localhost:8080/struts_test_1.0/first!add 或者敲入者http://localhost:8080/struts_test_1.0/first!update 的时候就出错了,提醒如下:

There is no Action mapped for namespace [/] and action name [first!add] associated with context path [/struts_test_1.0].

   
为什么会这样?怎么解决??求助
1 回复
#2
java小蚂蚁2013-10-15 15:24
你点击第一个网址的时候成功是因为execute是默认的。其他的都要你自己来配置相关的action,
1