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

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

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

    Struts之DispatchAction使用(錄像教程)

    Posted on 2005-12-04 10:46 oksonic 閱讀(8376) 評論(10)  編輯  收藏 所屬分類: java

    速動畫教程第十三集

     

    下載地址:http://sonic.peakle.net/download/sonic013.rar

     

    Struts 之 DispatchAction

     

    介紹

        DispatchAction就是在struts-config中用parameter參數配置一個表單字段名,這個字段的值就是最終替代execute被調用的方法。

        例如parameter="method"而request.getParameter("method")="save",其中"save"就是MethodName。struts的請求將根據parameter被分發到"save"或者"edit"或者什么。但是有一點,save()或者edit()等方法的聲明和execute必須一模一樣。

     

    新建工程:test

    添加Struts框架

     

    創建index.jsp

     

    按下Ctrl + N ,創建add.jspUsersAction.java

    ActionForm采用動態的ActionForm,所以繼承于DynaActionForm

    UserAction的內容將包含add、delall等方法,并且繼承于DispatchAction

     

    * 記得修改AddAction.java 為 UsersAction

     

    <action

          attribute="addForm"

          input="/add.jsp"

          name="addForm"

          parameter="method"

          path="/add"

          scope="request"

           validate="false"

          type="com.test.struts.action.UsersAction" />

     

    * 綠色字全部份為參數

     

    新建一個forward,名稱為indexGo,并指向index.jsp,Relative設置為true

     

    修改add.jsp文件

                  <html:form action="/add">

               username : <html:text property="username"/><html:errors property="username"/><br/>

               <html:submit onclick="document.forms[0].action='add.do?method=add';document.forms[0].submit();"/><html:cancel/>

           </html:form>

     

    * 綠色字為修改部份

    修改后的提交方式是帶參數提交的,不過必須點提交按鈕,如果是使用回車鍵的話就不會帶有參數

     

    修改UsersAction.java文件

    增加以下代碼:

        public ActionForward add(ActionMapping mapping, ActionForm form,

                HttpServletRequest request, HttpServletResponse response) {

            DynaActionForm addForm = (DynaActionForm) form;

            String username = addForm.getString("username");

            // 驗證用戶輸入

            if (username == null || username.length() < 1)

                mapping.getInputForward();

            HttpSession session = request.getSession();

            // 從session中獲得數據

            Vector users = (Vector) session.getAttribute("Users");

            if (users == null)

                users = new Vector();

            users.addElement(username);

            session.setAttribute("Users", users);

            return mapping.findForward("indexGo");

        }

     

     

    修改index.jsp文件,使頁面中可以顯示session中的數據,代碼如下:

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

    <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>

    <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>

    <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>

    <html>

      <head>

        <title>INDEX</title>

      </head>

     

      <body>

        <a href="add.jsp">ADD USER</a><br>

        <a href="delete.jsp">DELETE ALL</a><p>

        <logic:present name="Users">

        <logic:iterate id="element" name="Users">

            <bean:write name="element"/><br>

        </logic:iterate>

        </logic:present>

      </body>

    </html>

     

     

    按下Ctrl + N ,創建DellallAction.java,繼承于DispatchAction

    選中:Use existing Action class,瀏覽UsersAction

    選中:Parameter選項卡,填入method,然后完成

     

    現在修改index.jsp文件

    <a href="delete.jsp">DELETE ALL</a><p>

    改為

    <a href="delall.do?method=delall">DELETE ALL</a><p>

     

    修改UsersAction.java文件

    增加以下代碼:

        public ActionForward delall(

                ActionMapping mapping,

                ActionForm form,

                HttpServletRequest request,

                HttpServletResponse response) {

                HttpSession session=request.getSession();

                session.setAttribute("Users",null);

                return mapping.findForward("indexGo");

            }

     

    這一步很重要,execute 方法必須刪除!!!

     

    好了,可以進行測試了!!!

    Feedback

    # re: 速動畫教程第十三集Struts之DispatchAction  回復  更多評論   

    2005-12-05 10:53 by 鐵手
    So cool so good. pls go on. Supporting!

    # re: Struts之DispatchAction使用(錄像教程)  回復  更多評論   

    2006-01-08 18:58 by ooad
    感謝oksonic:
    你的例子我作了,很好,在此表示感謝!
     但是怎末解決回車不帶參數呢?
    還有就是我看到大部分都是繼承于LookUpDispatchAction 他們有什么區別呢??
    盼望回復.

    # re: Struts之DispatchAction使用(錄像教程)  回復  更多評論   

    2006-03-15 15:51 by xs
    不知道為什么我做的例子每次加進去兩條 ,請幫我解答一下。謝謝

    # re: Struts之DispatchAction使用(錄像教程)  回復  更多評論   

    2006-03-22 10:41 by achun
    感謝一下!

    # re: Struts之DispatchAction使用(錄像教程)  回復  更多評論   

    2006-03-31 18:38 by 雨來
    好偉大啊

    # re: Struts之DispatchAction使用(錄像教程)  回復  更多評論   

    2006-05-08 16:22 by lingdian
    樓主,為什么你的gmail里沒有這個的sonic013的文件啊!!!

    # re: Struts之DispatchAction使用(錄像教程)  回復  更多評論   

    2006-07-13 10:27 by abc
    * 綠色字為修改部份

    修改后的提交方式是帶參數提交的,不過必須點提交按鈕,如果是使用回車鍵的話就不會帶有參數

    -----------------請問如何解決回車提交 ?

    # re: Struts之DispatchAction使用(錄像教程)  回復  更多評論   

    2006-09-14 21:11 by hawks
    下面這段代碼
    <table align=center border="15" cellspacing="2" width="89%"> <br>
    <tr>
    <th>用戶名 </th><th>角色</th><th>刪除</th>
    </tr>
    <logic:iterate id="rs" name="queryResult">
    <tr>
    <form action="/searchAction.do?expression=<bean:write name='rs' property='username' />">
    <td><bean:write name="rs" property="username" /></td>
    <td><bean:write name="rs" property="role" /></td>
    <td>
    <html:submit value="remove" onclick="document.forms[0].action='searchAction.do?method=remove';document.form[0].submit();"/>
    </td>
    </form >
    </tr>
    </logic:iterate>
    </table>
    用form[0]不合適,需要一個變量,類似form[i],應該怎樣;或者是有其他的方法,例如bean:message。不知道怎么實現,請教樓主。

    # re: Struts之DispatchAction使用(錄像教程)  回復  更多評論   

    2006-12-18 14:54 by LeVaN
    http://www.anna-sen-soida-elastinen.beibi.info ^^^ http://www.anssi-22-vuosi-joensuu.beibi.info ^^^ http://www.eldre-masturbering-mpeg.biseksuell.info ^^^ http://www.film-prostituert-hetest.biseksuell.info ^^^ http://www.eldre-masturbering-mpeg.erotiska.info ^^^ http://www.film-prostituert-hetest.erotiska.info ^^^ http://www.film-snall-homosexuell.fitta69.info ^^^ http://www.videor-transsexuell-rakning.fitta69.info ^^^ http://www.sympatisk-foto-mpg.fotsex.info ^^^ http://www.naturlig-penis-klipp.fotsex.info ^^^ http://www.naida-gratissex.isomuna.info ^^^ http://www.uhkarohkea-poliisi-striptease.isomuna.info ^^^ http://www.sopo-tytot-vittu.laukeaminen.info ^^^ http://www.pelottava-lesbo-pano.laukeaminen.info ^^^ http://www.porno-kukk-jenter.rype.info ^^^ http://www.klipp-munnsex-strippe.rype.info ^^^ http://www.knulle-pornostjerne-porno.sadsprut.info ^^^ http://www.eksotisk-bitch-bilde.sadsprut.info ^^^ http://www.onnelliset-orgasmi.tytsy.info ^^^ http://www.latino-pillut-imeskella.tytsy.info ^^^ http://www.masturbation-creampie-ass.18analsex.com ^^^ http://www.anl-fucking-xxx.18analsex.com ^^^

    # re: Struts之DispatchAction使用(錄像教程)  回復  更多評論   

    2008-01-18 13:32 by 插兩條記錄的解決方法
    <html:button value="submit" property="submit" onclick="document.forms[0].action='record.do?method=add';document.forms[0].submit();"/><html:cancel/>

    posts - 103, comments - 1104, trackbacks - 0, articles - 0

    Copyright © oksonic

    主站蜘蛛池模板: 亚洲人成网站18禁止久久影院| 亚洲图片激情小说| 777成影片免费观看| 亚洲精品无码av片| 亚洲成A人片777777| 成年女人午夜毛片免费看| 日韩毛片在线免费观看| 亚洲丁香色婷婷综合欲色啪| 好大好硬好爽免费视频| 国产婷婷成人久久Av免费高清| 伊人久久五月丁香综合中文亚洲 | 亚洲AV一区二区三区四区| 国产亚洲AV无码AV男人的天堂| 久久不见久久见免费影院| 免费看无码特级毛片| 精品国产亚洲AV麻豆| 中文字幕视频免费| 欧洲乱码伦视频免费国产| 亚洲第一页在线视频| 亚洲综合精品香蕉久久网| 免费理论片51人人看电影| 亚洲国产精品免费视频| 农村寡妇一级毛片免费看视频 | 亚洲GV天堂无码男同在线观看| 亚洲精品成人片在线播放| 国产亚洲福利一区二区免费看| 57pao一国产成永久免费| 国产免费内射又粗又爽密桃视频| 亚洲国产成人99精品激情在线| 婷婷亚洲久悠悠色悠在线播放 | 亚洲av成人综合网| 亚洲欧洲第一a在线观看| 国产亚洲精aa成人网站| 国产午夜鲁丝片AV无码免费| 无码国产精品一区二区免费式直播| 中国人免费观看高清在线观看二区| 亚洲AV永久无码天堂影院| 亚洲三级中文字幕| 亚洲电影国产一区| 亚洲国产精品久久66| 亚洲精品色午夜无码专区日韩|