Posted on 2009-05-25 21:05
管贤春 阅读(342)
评论(0) 编辑 收藏 所属分类:
java
jsp页面代码:
<html:form action="/test">
<html:submit property="method">//要与struts-config.xml file中的parameter的值一致
<bean:message key="button.add"/>
</html:submit>
<html:submit property="method">
<bean:message key="button.delete"/>
</html:submit>
</html:form>
我们用action继承LookupDispatchAction类,实现getKeyMethodMap方法
public class MultiSubmitAction extends LookupDispatchAction
{
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("button.add", "add");//前一个参数要与jsp中的key一致,后一个就是要实现的方法名。
map.put("button.delete", "delete");
return map;
}
public ActionForward add(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// do add
return mapping.findForward("success");
}
public ActionForward delete(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// do delete
return mapping.findForward("success");
}
接下来就是要配置struts-config.xml file
<action path="/test"
type="org.example.MultiSubmitAction "
name="MultiSubmitForm"
scope="request"
input="/test.jsp"
parameter="method"/>//这里的parameter="method"要和jsp中的parameter="method"一致。
}