---
title: "（9）LookupDispatchAction"
author: "bolan392"
date: "2009-07-09T17:10:42Z"
tags: []
slug: "9-lookupdispatchaction"
draft: false
lastmod: "2009-07-09T17:11:21Z"
id: 422757
url: "https://bolan392.iteye.com/blog/422757"
---

1\. 创建资源信息文件，内容如下

button.save=save  
button.checkout=checkout  
index.username=UserName:

2\. 创建页面

&lt;html:form action="lookup.do"&gt;  
      &lt;bean:message key="index.username"/&gt;&lt;html:text property="name"&gt;&lt;/html:text&gt;  
   &lt;html:submit property="action"&gt;  
    &lt;bean:message key="button.save"/&gt;  
   &lt;/html:submit&gt;  
   &lt;html:submit property="action"&gt;  
    &lt;bean:message key="button.checkout"/&gt;  
   &lt;/html:submit&gt;  
&lt;/html:form&gt;

3. 创建一个类继承LookupDispatchAction并覆盖getKeyMethodMap()方法

public class MyLookUpAction extends LookupDispatchAction {  
 /*  
  * 该方法用来确定页面中提交按钮对应的业务方法(non-Javadoc)  
  * key:对应页面中&lt;bean:messgae&gt;标签的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属性要和页面中按钮的名称相同

         &lt;action  
      name="MyForm"  
      parameter="action"  
      path="/lookup"  
      type="com.rhcj.struts.MyLookUpAction" /&gt;