读书人

struts 1.x 跟通配符的使用 MappingD

发布时间: 2012-10-23 12:12:22 作者: rapoo

struts 1.x 和通配符的使用 MappingDispatchAction

环境多文件配置<?xml version="1.0" encoding="UTF-8"?>

?MappingDispatchAction配置文件

org.apache.struts.actions?
Class MappingDispatchAction
java.lang.Object  struts 1.x 跟通配符的使用  MappingDispatchActionorg.apache.struts.action.Action      struts 1.x 跟通配符的使用  MappingDispatchActionorg.apache.struts.actions.BaseAction          struts 1.x 跟通配符的使用  MappingDispatchActionorg.apache.struts.actions.DispatchAction              struts 1.x 跟通配符的使用  MappingDispatchActionorg.apache.struts.actions.MappingDispatchAction

public class MappingDispatchAction
extends DispatchAction

?

An abstract?Action?that dispatches to a public method that is named by the?parameter?attribute of the corresponding ActionMapping. This is useful for developers who prefer to combine many related actions into a single Action class.

To configure the use of this action in your?struts-config.xml?file, create an entry like this:

   <action path="/saveSubscription"           type="org.example.SubscriptionAction"           name="subscriptionForm"          scope="request"          input="/subscription.jsp"      parameter="method"/> 

where 'method' is the name of a method in your subclass of MappingDispatchAction that has the same signature (other than method name) of the standard Action.execute method. For example, you might combine the methods for managing a subscription into a single MappingDispatchAction class using the following methods:

?

例子通配符的使用

?Action 对像

package com.test.action;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.actions.MappingDispatchAction;public class TestAction extends MappingDispatchAction {//additionTestpublic ActionForward addTestAction(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response){request.setAttribute("usb", "Struts 1.x Addition Successful...");return mapping.findForward("add");}//additionTestpublic ActionForward deleteTestAction(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response){request.setAttribute("usb", "Struts 1.x Delete Successful...");return mapping.findForward("add");}//additionTestpublic ActionForward listTestAction(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response){request.setAttribute("usb", "Struts 1.x List Successful...");return mapping.findForward("add");}}
?

?

读书人网 >软件架构设计

热点推荐