![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
struts1 的动态调用方法问题
是struts1不是struts2的怎么调用一个action里除了默认的execute()方法以外的其他自定义的方法。struts2的好像有很多种方法如通配符之类的不过s...
是struts1 不是 struts2的
怎么调用一个action里除了默认的execute()方法以外的其他自定义的方法。 struts2的好像有很多种方法 如 通配符之类的 不过struts1的怎么办呢? 在form表单里写 action.do?method=xxx也不好是
我实在是查不出来了才来这问的 展开
怎么调用一个action里除了默认的execute()方法以外的其他自定义的方法。 struts2的好像有很多种方法 如 通配符之类的 不过struts1的怎么办呢? 在form表单里写 action.do?method=xxx也不好是
我实在是查不出来了才来这问的 展开
5个回答
展开全部
大体代码 没有导包
Action 继承 DispatchAction
public class UserAction extends DispatchAction{
private UserBO bo = new UserBOImpl() ;
public ActionForward add(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){
UserForm ff =(UserForm)form;
UserModel model = new UserModel();
try{
BeanUtils.copyProperties(model, ff) ;
}catch(Exception e){
e.printStackTrace() ;
}
bo.addUserModel(model) ;
ff.reset(mapping, request) ;
return mapping.findForward("search") ;
}
public ActionForward update(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){
UserForm ff =(UserForm)form;
UserModel model = new UserModel();
try{
BeanUtils.copyProperties(model, ff) ;
}catch(Exception e){
e.printStackTrace() ;
}
bo.updateUserModel(model) ;
return mapping.findForward("search") ;
}
}
在提交页面添加隐藏域
<html:hidden property="method" value="add"/>
当提交 到上面的 action 当中后 他就自动 去找 add 这个方法执行了
还有必须在mxl 当中配置
<action path="/userOperator" type="com.rhcj.customer.struts.action.UserAction"
name="userForm"
scope="request"
parameter="method"
validate="false">
<forward name="search" path="/customer/search.jsp"></forward>
</action>
parameter="method" 这个属性
Action 继承 DispatchAction
public class UserAction extends DispatchAction{
private UserBO bo = new UserBOImpl() ;
public ActionForward add(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){
UserForm ff =(UserForm)form;
UserModel model = new UserModel();
try{
BeanUtils.copyProperties(model, ff) ;
}catch(Exception e){
e.printStackTrace() ;
}
bo.addUserModel(model) ;
ff.reset(mapping, request) ;
return mapping.findForward("search") ;
}
public ActionForward update(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){
UserForm ff =(UserForm)form;
UserModel model = new UserModel();
try{
BeanUtils.copyProperties(model, ff) ;
}catch(Exception e){
e.printStackTrace() ;
}
bo.updateUserModel(model) ;
return mapping.findForward("search") ;
}
}
在提交页面添加隐藏域
<html:hidden property="method" value="add"/>
当提交 到上面的 action 当中后 他就自动 去找 add 这个方法执行了
还有必须在mxl 当中配置
<action path="/userOperator" type="com.rhcj.customer.struts.action.UserAction"
name="userForm"
scope="request"
parameter="method"
validate="false">
<forward name="search" path="/customer/search.jsp"></forward>
</action>
parameter="method" 这个属性
展开全部
Action 继承 DispatchAction
struts-config.xml文件的action中配置分发的参数 parameter="method"
并且Action中 execute()方法不能保留,否则只会执行它,而不会执行分发的方法
struts-config.xml文件的action中配置分发的参数 parameter="method"
并且Action中 execute()方法不能保留,否则只会执行它,而不会执行分发的方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
struts1用DispatchAction,分发器,就可以自己定义方法了。在页面传这个方法名字,就可以调用。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你把自己写Action 继承 DispatchAction
方法自己定义xxx()
在struts-config.xml里的<action parameter="method" >就可以了
form 里 action.do?method=xxx
就可以了!
方法自己定义xxx()
在struts-config.xml里的<action parameter="method" >就可以了
form 里 action.do?method=xxx
就可以了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Action 继承 DispatchAction 。MappingDispatchAction
具体用法自己查吧
具体用法自己查吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询