<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

    主站蜘蛛池模板: 一级做a爰片久久毛片免费陪 | 无码人妻一区二区三区免费看| 啊v在线免费观看| 亚洲精品无码永久在线观看男男| 最近中文字幕mv免费高清在线| 亚洲va无码va在线va天堂| 国产午夜精品理论片免费观看| 青青草原亚洲视频| 两个人看www免费视频| 亚洲av永久无码精品漫画| 青青操视频在线免费观看| 亚洲国产成人精品无码区在线观看 | 成人免费看黄20分钟| 亚洲精品精华液一区二区| 欧洲美熟女乱又伦免费视频| 日韩欧美亚洲中文乱码| 高清在线亚洲精品国产二区| 成人免费网站久久久| 久久精品国产亚洲麻豆| 99爱在线精品视频免费观看9| 亚洲天堂一区在线| 情侣视频精品免费的国产| 又大又硬又粗又黄的视频免费看| 红杏亚洲影院一区二区三区| 日本免费在线观看| 亚洲区精品久久一区二区三区| 成人人免费夜夜视频观看| 免费人成网站永久| 亚洲国产a∨无码中文777| 13一14周岁毛片免费| 亚洲人成网站18禁止| 亚洲片国产一区一级在线观看 | **aaaaa毛片免费| 亚洲日韩中文字幕无码一区| 亚洲国产精品尤物yw在线 | aa毛片免费全部播放完整| 久久精品国产亚洲AV高清热| 青青青国产免费一夜七次郎| 一区二区三区免费视频观看| 中文字幕亚洲综合精品一区| 国产真实伦在线视频免费观看|