1. 创建资源信息文件,内容如下
button.save=save
button.checkout=checkout
index.username=UserName:
2. 创建页面
<html:form action="lookup.do">
<bean:message key="index.username"/><html:text property="name"></html:text>
<html:submit property="action">
<bean:message key="button.save"/>
</html:submit>
<html:submit property="action">
<bean:message key="button.checkout"/>
</html:submit>
</html:form>
3. 创建一个类继承LookupDispatchAction并覆盖getKeyMethodMap()方法
public class MyLookUpAction extends LookupDispatchAction {
/*
* 该方法用来确定页面中提交按钮对应的业务方法(non-Javadoc)
* key:对应页面中<bean:messgae>标签的key属性
* value:对应该类中具体业务方法名称
*/
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("button.save", "save1");
map.put("button.checkout","checkout1" );
return map;
}
4. 在Action中添加业务逻辑方法
public ActionForward save1(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("Save()......");
return null;
}
public ActionForward checkout1(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("Checkout()......");
return null;
}
5. 在struts-config.xml中 配置Action,该Action的parameter属性要和页面中按钮的名称相同
<action
name="MyForm"
parameter="action"
path="/lookup"
type="com.rhcj.struts.MyLookUpAction" />