`
hilly
  • 浏览: 51621 次
  • 性别: Icon_minigender_1
  • 来自: **
社区版块
存档分类
最新评论

LookupDispatchAction使用示例

阅读更多
LookupDispatchAction

public abstract class LookupDispatchAction
extends DispatchAction

An abstract Action that dispatches to the subclass mapped execute method. This is useful in cases where an HTML form has multiple submit buttons with the same name. The button name is specified by the parameter property of the corresponding ActionMapping. To configure the use of this action in your struts-config.xml file, create an entry like this:

   <action path="/test"
           type="org.example.MyAction"
           name="MyForm"
          scope="request"
          input="/test.jsp"
      parameter="method"/>
 

which will use the value of the request parameter named "method" to locate the corresponding key in ApplicationResources. For example, you might have the following ApplicationResources.properties:

    button.add=Add Record
    button.delete=Delete Record
  

And your JSP would have the following format for submit buttons:

   <html:form action="/test">
    <html:submit property="method">
      <bean:message key="button.add"/>
    </html:submit>
    <html:submit property="method">
      <bean:message key="button.delete"/>
    </html:submit>
  </html:form>
  

Your subclass must implement both getKeyMethodMap and the methods defined in the map. An example of such implementations are:

  protected Map getKeyMethodMap() {
      Map map = new HashMap();
      map.put("button.add", "add");
      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");
  }
  

Notes - If duplicate values exist for the keys returned by getKeys, only the first one found will be returned. If no corresponding key is found then an exception will be thrown. You can override the method unspecified to provide a custom handler. If the submit was cancelled (a html:cancel button was pressed), the custom handler cancelled will be used instead.

 

分享到:
评论

相关推荐

    DispatchAction、LookupDispatchAction、SwitchAction的应用

    **2.2 使用示例** 假设有一个编辑文章的表单,其中包含“保存”和“取消”两个按钮,这两个按钮都使用相同的名称 `action`: ```xml ****.EditArticleAction" name="ArticleForm" scope="request" parameter=...

    struts LookupdispathAction类使用实例

    5. **使用示例** - 创建一个 `MyLookupDispatchAction` 类,继承自 `LookupDispatchAction`。 - 在类中定义如 `doSave()`, `doLoad()`, `doUpdate()` 等方法,分别处理保存、加载和更新操作。 - 在 `struts-...

    J2EE_高级Action

    在Web开发中,特别是使用Struts框架时,经常会遇到一个问题:当一个简单的组件(如购物车)需要执行多种操作(如添加商品、删除商品、修改商品数量等),而Struts的`Action`类通常只有一个`execute`方法时,如何设计...

    轻量级J2EE企业应用实战源码 3 下

    1. **LookupDispatchAction**: 这个文件可能涉及到Struts框架中的`LookupDispatchAction`,这是一个用于处理多视图的Action,它可以根据用户请求的参数来决定调用哪个业务方法。这在实现复杂的视图跳转和逻辑控制时...

    Struts开发指南03

    LookupDispatchAction则能根据提交表单按钮的名称来调用相应的方法。 在Struts的工作流程中,一旦Action执行完毕,它会返回一个ActionForward对象。ActionForward代表一个URL,指示下一步应该去哪里,可以是另一个...

    struts1.x技术课程讲解.pdf

    - **LookUpDispatchAction**:与 DispatchAction 类似,但更灵活,可以动态地确定方法名。 2. **ActionServlet**:Struts1.x 的核心组件,负责初始化框架、接收 HTTP 请求并将请求分发给相应的 Action 类处理。 3. ...

    struts2.0之action

    以示例代码为例,`HelloWorld`类继承了`ActionSupport`,并重写了`execute()`方法。在`execute()`中,我们设置了消息并返回`SUCCESS`字符串,这告诉Struts框架这次操作成功并可以继续执行相应的视图解析。在`struts....

    EventDispatchAction类处理一个form多个submit

    与`LookupDispatchAction`相比,它的使用更为便捷,无需与属性文件关联,也不需要手动在`getKeyMethodMap`方法中进行key和Action方法的映射。 #### 三、EventDispatchAction的工作原理 `EventDispatchAction`通过`...

Global site tag (gtag.js) - Google Analytics