关于一个Form对应多个Action
背景:修改的页面有修改,新增两个功能。都得需要提交这个表单。
解决:例子,分页参数的传递,使用了隐藏变量
jsp
<html:submit property="action"><bean:message key="button.select"/></html:submit>
<html:submit property="action"><bean:message key="button.prePage"/></html:submit>
<html:submit property="action"><bean:message key="button.nextPage"/></html:submit>
struts-config.xml
<action path="/showHolidayIndex"
name="HolidayFormBean"
validate="false"
input="/pages/holiday/holiday_index.jsp"
attribute="HolidayFormBean"
type="com.mgs.MGSkentai.action.holiday.HolidayAction"
parameter="action"
scope="request">
<forward name="showdata" path="/pages/holiday/holiday_index.jsp"></forward>
</action>
Action
public class HolidayAction extends LookupDispatchAction {
//page
private static int MAX_RECORD = 10;
private int begin = 0;
private int end = 0;
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("button.select", "BeginSearch");
map.put("button.prePage", "PrePage");
map.put("button.nextPage", "NextPage");
return map;
}
public ActionForward BeginSearch(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
return mapping.findForward("showdata");
}
public ActionForward PrePage(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
return mapping.findForward("showdata");
}
public ActionForward NextPage(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
return mapping.findForward("showdata");
}
}
PS: 有更好的方法的话~欢迎大家给意见~谢谢~