本文转载请标明出处:
作者:大灰狼
博客:http://www.gold98.net/blog
主页:http://www.gold98.net
今天小试了一下struts中的DispatchAction,现在来做个小小的总结:
首先我们要将Action的继承关系改为:
public class User_hibernateAction extends DispatchAction {
下面就是各种方法的实现了:
public ActionForward AddUser(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
public ActionForward updateUser(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
.......
这里实现了以后,
我们还要修改配置文件:
<action attribute="user_hibernateForm"
path="/hibernateAction"
type="com.zb.struts.action.User_hibernateAction"
parameter="method" name="user_hibernateForm"
scope="request"
input="/user_hibernate/userlist.
jsp"
>
<forward name="edit" path="/user_hibernate/edituser.
jsp" />
<forward name="editok" path="/user_hibernate/userlist.
jsp" />
基本跟原来的一样,只是添加了parameter,这个是必须的,上面已经用红色标记出来了;
接下来就是调用了~
在form的action中,我们一般直接写配置文件中的path就Ok了,如上例:action="/hibernateAction"
但如果是在<a href中的话,这个path我们就要稍作修改了:
假如你的web应用名称叫test,那么就应该写成: /test/hibernateAction.do
这个.do好像不能少,因为至少我试的时候是这样的,这地方很容易被忽略,所以很容易出现找不到路径的错误~
如果我们要调用添加用户的方法则写成: /test/hibernateAction.do?method=AddUser