struts的action问题 我在用struts的过程中,发现有的时候只用一个action,在这个action中做一下if判断就能执行不同的请求,同时也可以用多个action来处理请求,那么,如何来做才算更好呢??thanks!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一个好点,但是不要把一个action写的太庞大 //当然是一个好了,写太多action根本就是在做无用功阿,没必要在这浪费时间//可以用一个action来处理所有的xxx.do//先写如下一个DispatchAction类public class MyDispatchAction extends DispatchAction { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String actionMethod = mapping.getParameter(); if (actionMethod == null) { return null; } return dispatchMethod(mapping, form, request, response, actionMethod); }}//再写一个action继承上面的DispatchAction类public class MyAction extends MyDispatchAction { public ActionForward xxx1(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { return mapping.findForward("xxx"); } public ActionForward xxx2(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { return mapping.findForward("xxx"); }}//每一个请求[xxx.do]对应第二个类中的一个方法,还需要在struts-config.xml中配置一下<action path="/xxx" type="com.action.MyAction" name="xxx" parameter="xxx1" //指定"com.action.MyAction"类中哪个方法来处理,就是方法名 scope="request"> <forward name="xxx" path="/xxx.jsp" /></action> 关于Struts2中的namespace的问题 请教各位高手 急急急!!! 一个SSH的在线考试系统出错,请求帮忙! Hibernate synchronizer从哪里可以下载到呀? 如何实现在线编译程序问题 用javamail发信为何连不上服务器 怎么让JSERV支持SERVLET2.2??? iplanet jsp页面刷新问题 该怎么做?帮帮忙。 jsp 能在IIS上用吗,仅有IIS 那位英雄赖帮帮我啊?? 一个关于数据库连接池的问题,请大家指教
//可以用一个action来处理所有的xxx.do//先写如下一个DispatchAction类public class MyDispatchAction extends DispatchAction {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception { String actionMethod = mapping.getParameter(); if (actionMethod == null) {
return null;
}
return dispatchMethod(mapping, form, request, response, actionMethod);
}
}
//再写一个action继承上面的DispatchAction类public class MyAction extends MyDispatchAction { public ActionForward xxx1(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
return mapping.findForward("xxx");
}
public ActionForward xxx2(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
return mapping.findForward("xxx");
}
}//每一个请求[xxx.do]对应第二个类中的一个方法,还需要在struts-config.xml中配置一下<action path="/xxx"
type="com.action.MyAction" name="xxx"
parameter="xxx1" //指定"com.action.MyAction"类中哪个方法来处理,就是方法名
scope="request">
<forward name="xxx" path="/xxx.jsp" />
</action>