写个Action继承LookupDispatchAction:
public class DoNothingAction extends LookupDispatchAction {
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("ADD method was invoked.");
return mapping.findForward("index");
}
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("UPDATE method was invoked.");
return mapping.findForward("index");
}
@Override
protected Map getKeyMethodMap() {
Map map = new HashMap();
// map的key是资源文件中配置的key,value则是方法名
map.put("button.add", "add");
map.put("button.update", "update");
return map;
}
}
ApplicationResources.properties文件中这样写:
button.add=Add
button.update=Update
struts-config.xml中这样配置:
<action path="/doNothing" type="com.yourcompany.struts.action.DoNothingAction"
parameter="method"
scope="request">
<forward name="index" path="/index.jsp"></forward>
</action>
页面中这样用:
<form action="doNothing.do">
<html:submit property="method"><bean:message key="button.add"/></html:submit>
<html:submit property="method"><bean:message key="button.update"/></html:submit>
</form>
到这,几个常用的Action就讲完了。