<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 閱讀(8384) 評論(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.jsp、UsersAction.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

    主站蜘蛛池模板: 亚洲日本国产精华液| 美女视频黄.免费网址| 影音先锋在线免费观看| 伊人久久国产免费观看视频| 亚洲情XO亚洲色XO无码| 国产精品免费精品自在线观看| 亚洲AV日韩AV永久无码色欲| 亚洲综合无码AV一区二区| 狼群影院在线观看免费观看直播 | 亚洲日本成本人观看| 国产国拍亚洲精品福利| 16女性下面扒开无遮挡免费| 欧美亚洲精品一区二区| 亚洲视频在线视频| 在线a亚洲v天堂网2018| 成人免费的性色视频| 巨胸狂喷奶水视频www网站免费| 亚洲最大的黄色网| 国产亚洲精品va在线| 日韩中文字幕在线免费观看| 久久精品中文字幕免费| 深夜福利在线免费观看| 亚洲乱码卡一卡二卡三| 国产国拍亚洲精品mv在线观看| 日本一区二区三区日本免费| 免费A级毛片无码专区| 七次郎成人免费线路视频| 亚洲国产成人精品激情| 久久夜色精品国产嚕嚕亚洲av| 国产乱子伦精品免费女| 波多野结衣在线免费观看| 免费人成在线观看视频高潮| 精品一区二区三区无码免费直播| 亚洲熟妇无码久久精品| 亚洲AV无码乱码在线观看富二代 | 日韩精品视频免费观看| 久草免费在线观看视频| 99久久99久久精品免费观看| 国产免费内射又粗又爽密桃视频| 亚洲精品自偷自拍无码| 亚洲Av高清一区二区三区|