隨筆 - 312, 文章 - 14, 評論 - 1393, 引用 - 0
          數據加載中……

          Struts1.x系列教程(21):使用MappingDispatchAction類調用不同的Action方法

          本文為原創,如需轉載,請注明作者和出處,謝謝!

          上一篇:Struts1.x系列教程(20):使用EventDispatchAction類處理一個form多個submit   

              與LookupDispatchAction、DispatchAction不同,MappingDispatchAction類并不通過請求參數來指定動作,而是將一個Struts動作對應于一個Action方法。下面的例子演示了如何使用MappingDispatchAction類來將Struts動作和Action方法相對應。

          Action類的實現代碼:

          package action;
          import org.apache.struts.actions.MappingDispatchAction;
           
          public class MyMappingDispatchAction extends MappingDispatchAction
          {
              public ActionForward pdf(ActionMapping mapping, ActionForm form,
                  HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException 
              {
                  //  生成pdf文件
              }
              public ActionForward html(ActionMapping mapping, ActionForm form,
                  HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException
              {
                  //  生成html文件
              }
              public ActionForward unspecified(ActionMapping mapping, ActionForm form,
                  HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException 
              {
                 
          //  處理默認動作
              }
          }

          上面的代碼有兩個Action方法:pdfhtml,分別用來生成pdfhtml文件。還有一個unspecified方法用來處理默認動作。
              我們可以使用如下的代碼來配置MyMappingDispatchAction類:

           

          <action path="/pdf" type = "action.MyMappingDispatchAction" parameter="pdf" />
          <action path="/html" type = "action.MyMappingDispatchAction" parameter="html" />

               可以通過如下的URL來訪問pdf和html動作,分別會調用MyMappingDispatchAction類的pdf和html方法:

          http://localhost:8080/samples/pdf.do

          http://localhost:8080/samples/html.do


          下一篇:Struts1.x系列教程(22):Tiles框架簡介





          Android開發完全講義(第2版)(本書版權已輸出到臺灣)

          http://product.dangdang.com/product.aspx?product_id=22741502



          Android高薪之路:Android程序員面試寶典 http://book.360buy.com/10970314.html


          新浪微博:http://t.sina.com.cn/androidguy   昵稱:李寧_Lining

          posted on 2009-02-24 19:55 銀河使者 閱讀(2928) 評論(0)  編輯  收藏 所屬分類: javaweb 原創struts1.x

          主站蜘蛛池模板: 瑞昌市| 兴山县| 泰和县| 浦东新区| 莆田市| 开鲁县| 辉县市| 阿拉尔市| 四川省| 平安县| 巴林左旗| 平度市| 思茅市| 高雄县| 诏安县| 榕江县| 宁海县| 萍乡市| 永修县| 华安县| 鸡西市| 金溪县| 奉化市| 敦煌市| 海兴县| 育儿| 宜州市| 海伦市| 翼城县| 淳化县| 长岛县| 雷山县| 松原市| 舞阳县| 抚州市| 全州县| 南陵县| 墨脱县| 洛隆县| 桐梓县| 图片|