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

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

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

    基于Struts的AJAX

    首先,我們仍然是對Struts應用來做配置,仍然是在struts-config,xml文件里做配置,如下:

     <action type="com.ajax.CheckAction"
         scope="request" path="/ajax/check">
         <forward name="success" path="/check.jsp"/>
     </action>


    跟普通的Struts應用的配置一樣,只是沒有ActionForm的配置。下面是Action類:

     package com.ajax;
     
     import java.io.PrintWriter;
     
     import javax.servlet.http.HttpServletRequest;
     import javax.servlet.http.HttpServletResponse;
     
     import org.apache.struts.action.Action;
     import org.apache.struts.action.ActionForm;
     import org.apache.struts.action.ActionForward;
     import org.apache.struts.action.ActionMapping;
     import org.apache.struts.action.DynaActionForm;
     
     /**
      * @author Administrator
      *
      * TODO To change the template for this generated type comment go to
      * Window - Preferences - Java - Code Style - Code Templates
      */
     public class CheckAction extends Action
     {
      public final ActionForward execute(ActionMapping mapping, ActionForm form,
               HttpServletRequest request,
               HttpServletResponse response)
       throws Exception
       {
      System.out.println("haha...............................");
      String username= request.getParameter("username");
      System.out.println(username);
      String retn;
      if("educhina".equals(username)) retn = "Can't use the same name with the old use,pls select a difference...";
      else retn = "congraducation!you can use this name....";
      PrintWriter out=response.getWriter();
               out.write(retn);
               out.close();
      return mapping.findForward("success");
       }
      public static void main(String[] args)
      {
      }
     }

    我們可以看到里面的邏輯跟上例中Servlet里的邏輯一樣。最后,我們來看看JSP:

     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
     <html>
     <head>
     <title>Check.html</title>
     
     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
     <meta http-equiv="description" content="this is my page">
     
     <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
     
     </head>
     <script type="text/javascript">
      var http_request = false;
      function send_request(url) {//初始化、指定處理函數、發送請求的函數
       http_request = false;
      
    file://開始初始化XMLHttpRequest對象
       if(window.XMLHttpRequest) {
    file://Mozilla 瀏覽器
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) {//設置MiME類別
       http_request.overrideMimeType('text/xml');
      }
       }
       else if (window.ActiveXObject) { // IE瀏覽器
      try {
       http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
       try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (e) {}
      }
       }
       if (!http_request) { // 異常,創建對象實例失敗
      window.alert("不能創建XMLHttpRequest對象實例.");
      return false;
       }
       http_request.onreadystatechange = processRequest;
       // 確定發送請求的方式和URL以及是否同步執行下段代碼
       http_request.open("GET", url, true);
       http_request.send(null);
      }
      // 處理返回信息的函數
       function processRequest() {
           if (http_request.readyState == 4) { // 判斷對象狀態
               if (http_request.status == 200) { // 信息已經成功返回,開始處理信息
                   alert(http_request.responseText);
               } else {
    file://頁面不正常
                   alert("您所請求的頁面有異常。");
               }
           }
       }
      function userCheck() {
       var f = document.forms[0];
       var username = f.username.value;
       if(username=="") {
      window.alert("The user name can not be null!");
      f.username.focus();
      return false;
       }
       else {
      send_request('ajax/check.do?username='+username);
       }
      }
     
     </script>
     <body>
      <form name="form1" action="" method="post">
     User Name:<input type="text" name="username" value="">&nbsp;
     <input type="button" name="check" value="check" onClick="userCheck()">
     <input type="submit" name="submit" value="/oblog312/submit">
     </form>
     </body>
     </html>

    我們可以看到,JSP基本是一樣的,除了要發送的url:ajax/check.do?username="+username。 

    posted on 2007-08-13 17:24 劉錚 閱讀(289) 評論(0)  編輯  收藏 所屬分類: Struts


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    <2025年7月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    導航

    統計

    留言簿(1)

    文章分類(141)

    文章檔案(147)

    搜索

    最新評論

    主站蜘蛛池模板: 成年性午夜免费视频网站不卡 | 亚洲精品91在线| 怡红院免费全部视频在线视频| 国产在线观看免费视频播放器| 亚洲精品无码你懂的| 成人免费福利电影| 亚洲美国产亚洲AV| 永久中文字幕免费视频网站| 亚洲AV无码一区二区三区鸳鸯影院 | 国产亚洲精品看片在线观看 | 免费播放一区二区三区| 亚洲AV人人澡人人爽人人夜夜 | 美女视频黄是免费的网址| 久久精品国产亚洲AV久| 成人免费777777| 天天综合亚洲色在线精品| 亚洲国产综合精品一区在线播放| 一级毛片免费播放男男| 亚洲一区二区精品视频| 91在线视频免费观看| 亚洲午夜视频在线观看| 最近最新MV在线观看免费高清| 亚洲精品无码专区在线| 亚洲国产精品综合久久网络| 好湿好大好紧好爽免费视频| 亚洲av无码一区二区三区不卡| 最近免费最新高清中文字幕韩国| 亚洲制服丝袜一区二区三区| 四虎成人精品在永久免费| 男女一边桶一边摸一边脱视频免费| 久久精品国产亚洲AV麻豆王友容| 在线观看成人免费视频不卡| 亚洲AV成人无码网天堂| 亚洲欧洲自拍拍偷午夜色无码| 最近免费中文字幕高清大全| 色婷婷六月亚洲综合香蕉| 激情97综合亚洲色婷婷五| 美丽的姑娘免费观看在线播放 | 99久久久国产精品免费牛牛四川| 亚洲国产精品嫩草影院| 国产亚洲日韩一区二区三区|