当前位置: 代码迷 >> Java Web开发 >> 关于struts2 动态action 的问题
  详细解决方案

关于struts2 动态action 的问题

热度:464   发布时间:2013-10-10 19:04:52.0
关于struts2 动态action 的问题
下面是我的struts2.xml的配置,有一个action :

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

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

   
为什么会这样?怎么解决??求助
搜索更多相关主题的帖子: default  Software  version  package  action  

----------------解决方案--------------------------------------------------------
你点击第一个网址的时候成功是因为execute是默认的。其他的都要你自己来配置相关的action,
----------------解决方案--------------------------------------------------------
  相关解决方案