<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 15,  comments - 8,  trackbacks - 0
    java.lang.Object

        org.apache.struts.action.Action

            org.apache.struts.actions.DispatchAction

                org.apache.struts.actions.LookupDispatchAction(Struts1.
    1)

                org.apache.struts.actions.EventDispatchAction(Struts1.
    2.9)

                org.apache.struts.actions.MappingDispatchAction(Struts1.
    2)


    DispatchAction
    public abstract class DispatchAction extends Action


    這是一個抽象的Action,它會根據request 中的parameter來執行相應的方法。通個這個Action類可以將不同的Action集中到一個Action文件中來。

    struts-config.xml:


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

    在Action中要有相應的方法:


    public class SubscriptionAction extends DispatchAction {
       
        
    public ActionForward delete(ActionMapping mapping, ActionForm form,
                                    HttpServletRequest request,
                                    HttpServletResponse response) 
    throws Exception {}
        
        
    public ActionForward insert(ActionMapping mapping, ActionForm form,
                                    HttpServletRequest request,
                                    HttpServletResponse response) 
    throws Exception {}
        
        
    public ActionForward update(ActionMapping mapping, ActionForm form,
                                    HttpServletRequest request,
                                    HttpServletResponse response) 
    throws Exception {}
        
    }

    然后可以通過這樣的方法來訪問你的程序:

    http://localhost:8080/myapp/subscription.do?method=delete

    http://localhost:8080/myapp/subscription.do?method=insert

    http://localhost:8080/myapp/subscription.do?method=update

    如果parameter中參數為空,則調用Action中的unspecified方法



    LookupDispatchAction
    public abstract class LookupDispatchAction extends DispatchAction


    通過這個Action抽象類繼承DispatchAction,它的相應方法的執行由ActionMapping中parameter屬性決定。每個動作實際上就是<html:submit>標簽的property屬性值。它適合在一個form中有很多按鈕,按不同的按鈕則執行不同的操作。

    struts-config.xml:


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

    ApplicationResources.properties:

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

    JSP:

    <%@ page pageEncoding="GBK"%>
    <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
    <html>
      
    <head>
        
    <title>多提交演示</title>
      
    </head>
      
    <body>
        
    <html:form action="subscription"> 
          
    <html:submit property="method"> 
            
    <bean:message key="button.add"/> 
          
    </html:submit> 
          
    <html:submit property="method"> 
            
    <bean:message key="button.delete"/> 
          
    </html:submit> 
        
    </html:form>
      
    </body> 
    </html>

    在Action中必須實現getKeyMethodMap方法:

    public class SubscriptionAction extends LookupDispatchAction {

        
    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 Exception {}

        
    public ActionForward delete(ActionMapping mapping,
                                    ActionForm form,
                                    HttpServletRequest request,
                                    HttpServletResponse response) 
    throws Exception {}

    }


    EventDispatchAction
    public class EventDispatchAction extends DispatchAction


    通過這個Action抽象類繼承DispatchAction,它的相應方法的執行由ActionMapping中parameter屬性指定多個動作,中間用逗號(,)分隔。每個動作實際上就是<html:submit>標簽的property屬性值。它適合在一個form中有很多按鈕,按不同的按鈕則執行不同的操作。

    struts-config.xml:

    (parameter中的"recalc=recalculate"意思為<html:submit>標簽的property屬性值為recalc調用recalculate方法,出于安全考慮能夠隱藏后臺的業務方法名。"defaule=save"這是可選的,沒有配置property屬性的<html:submit>標簽將調用defaule中設置的方法名,如果defaule沒有指定任何參數,則調用Action中的unspecified方法)


    <action path="/subscription" type="org.example.SubscriptionAction" name="subscriptionForm" scope="request"
    input
    ="/subscription.jsp" parameter="save,back,recalc=recalculate,default=save"/>


    JSP:

    <%@ page pageEncoding="GBK"%>
    <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
    <html>
      
    <head>
        
    <title>多提交演示</title>
      
    </head>
      
    <body>           
        
    <html:form action="subscription">
          
    <html:submit property="save" value="保存"/>
          
    <html:submit property="back" value="后退"/>
          
    <html:submit property="recalc" value="重新計算"/>
        
    </html:form>  
      
    </body> 
    </html>

    在Action中要有相應的方法:


    public class SubscriptionAction extends LookupDispatchAction {

        
    public ActionForward save(ActionMapping mapping,
                                  ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response) 
    throws Exception {}

        
    public ActionForward back(ActionMapping mapping,
                                  ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response) 
    throws Exception {}

        
    public ActionForward recalculate(ActionMapping mapping,
                                         ActionForm form,
                                         HttpServletRequest request,
                                         HttpServletResponse response) 
    throws Exception {}

    }


    MappingDispatchAction
    public class MappingDispatchAction extends DispatchAction


    它的相應方法的執行由ActionMapping中parameter名決定,注意這里和LookupDispatchAction不同,LookupDispatchAction的相應方法的執行由ActionMapping中parameter屬性決定。

    struts-config.xml:


    <action path="/createSubscription" type="org.example.SubscriptionAction" parameter="create"> 
          
    <forward name="success" path="/createSubscription.jsp"/> 
    </action>
    <action path="/editSubscription" type="org.example.SubscriptionAction" parameter="edit"> 
          
    <forward name="success" path="/editSubscription.jsp"/> 
    </action>
    <action path="/saveSubscription" type="org.example.SubscriptionAction" parameter="save"
    name
    ="subscriptionForm" validate="true" input="/editSubscription.jsp" scope="request"> 
          
    <forward name="success" path="/savedSubscription.jsp"/> 
    </action>
    <action path="/deleteSubscription" type="org.example.SubscriptionAction" name="subscriptionForm"
    scope
    ="request" input="/subscription.jsp" parameter="delete"> 
          
    <forward name="success" path="/deletedSubscription.jsp"/> 
    </action>
    <action path="/listSubscriptions" type="org.example.SubscriptionAction" parameter="list"> 
          
    <forward name="success" path="/subscriptionList.jsp"/>
    </action>

    在Action中要有相應的方法:

    public class SubscriptionAction extends MappingDispatchAction {

        
    public ActionForward create(ActionMapping mapping, ActionForm form,
                                    HttpServletRequest request,
                                    HttpServletResponse response) 
    throws Exception {}


        
    public ActionForward edit(ActionMapping mapping, ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response) 
    throws Exception {}


        
    public ActionForward save(ActionMapping mapping, ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response) 
    throws Exception {}


        
    public ActionForward delete(ActionMapping mapping, ActionForm form,
                                    HttpServletRequest request,
                                    HttpServletResponse response) 
    throws Exception {}


        
    public ActionForward list(ActionMapping mapping, ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response) 
    throws Exception {}

    }

    然后可以通過這樣的方法來訪問你的程序

    http://localhost:8080/myapp/create.do

    http://localhost:8080/myapp/edit.do

    http://localhost:8080/myapp/save.do

    http://localhost:8080/myapp/delete.do

    http://localhost:8080/myapp/list.do

    如果parameter中參數為空,則調用Action中的unspecified方法

    posted on 2009-02-25 17:42 lvq810 閱讀(943) 評論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 亚洲国产精品成人精品小说| 亚洲一区二区三区无码影院| 久久久久亚洲AV成人片| 中文字幕不卡免费视频| 久久久亚洲精品蜜桃臀| 国产精品永久免费| 久久亚洲av无码精品浪潮| 国产高潮流白浆喷水免费A片 | 国产成人免费A在线视频| 在线看亚洲十八禁网站| 免费永久看黄在线观看app| 美女的胸又黄又www网站免费| 全黄性性激高免费视频| A国产一区二区免费入口| 国产国拍亚洲精品mv在线观看| 久久国产乱子伦精品免费看| 亚洲AV无码专区在线播放中文 | 女bbbbxxxx另类亚洲| 亚洲爽爽一区二区三区| a国产成人免费视频| 亚洲精品一卡2卡3卡三卡四卡| 在线看片无码永久免费视频| 亚洲国产成人无码AV在线| 亚洲精品乱码久久久久久蜜桃 | 四虎影视久久久免费| 亚洲中久无码永久在线观看同| 久久久久久久岛国免费播放| 亚洲欧洲自拍拍偷午夜色| 日本视频免费在线| 花蝴蝶免费视频在线观看高清版 | 无码精品人妻一区二区三区免费看| 久久亚洲AV成人无码| 青草草在线视频永久免费| 美女被免费网站91色| 亚洲人6666成人观看| 亚洲国产一区视频| 最近免费视频中文字幕大全| 亚洲AV无码AV日韩AV网站| 久久精品亚洲一区二区| 日本高清免费网站| 久草免费福利资源站|