struct-config.xml 中 action的parameter属性设置

来源:百度知道 编辑:UC知道 时间:2024/09/27 08:12:55
<html:link action="myTest.do?method=insert">11111</html:link>
myTest.do 和 method 这些在struct-config.xml如何定义
/*------------------------------
<action attribute="roleForm" name="roleForm" path="/role"
scope="request" type="action.RoleAction"
parameter="method" />
在JSP 页面 如果参数 method = init 那将调用RoleAction中的 public ActionForward init()方法
-------------------------------*/
以上是一个网友的解释.我按他说的设置后,并没有调用init方法.
请问:
1.<html:form action="/myTest.do?method=insert" >....
<html:link action="myTest.do?method=insert">11111</html:link>
这2种方式下如何编写,设置才能调用我预定义的insert处理方法.<html:form>标签中是否还需要写method="post/get"
2.如果这么设置是否还需要继承别的其他类
希望高人指点.

<action>的parameter属性是给DispatchAction使用的,你的类要继承DispatchAction类,而不是普通的Action,Action只会执行execute方法,DispatchAction会根据parameter的值执行特定的方法,注意parameter的值不要设置为execute,也不要覆盖DispatchAction中的execute(),因为DispatchAction继承于Action,它的execute会首先执行,在execute()方法中取出parameter的值,通过java反射调用指定的方法。

页面设置基本这样就可以了.如果是form中这样可以
<html:form action="/myTest.do?method=insert" metho="post">.
如果是超链 这样可以
<a herf="myTest.do?method=insert"">1111</a>
另外action必须是extens dispatchaction的.

这个是Struts的DispatchAction机制,
简单描述:
一个Action通常只能完成一种业务操作,如果你想在一个Action里处理多个业务请求,那么可以使用DispatchAction
只不过再配置Action的时候需要设置parameter="your_method";
请求时这样写http://localhost:8080/test.do?your_method=init
其中init是你继承DispatchAction的Action类的一个业务操作,
如果你的Action类写的不是继承DispatchAction的话,你的设置就没用了,有两种方法要么改配置去掉parameter="method&q