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

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

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

    如何學(xué)好java

    如何學(xué)好java,其實(shí)很簡單,只要用心體會,慢慢積累!
    posts - 106, comments - 7, trackbacks - 0, articles - 3
      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    ajax

    Posted on 2012-05-25 16:43 哈希 閱讀(234) 評論(0)  編輯  收藏 所屬分類: Js and Jquery 常用總結(jié)

    網(wǎng)上的 Jquery ajax Demo 大多都是基于php
    很少 有java的 今天就把自己的Demo貼出來 和大家共同學(xué)習(xí)
    現(xiàn)在就  Jquery ajax 的 $.ajax(),$.post(),$.get();

    首先是  服務(wù)端的Servlet 演示這三個(gè)函數(shù)的用法對都是用的同一個(gè) 服務(wù)端
    Java代碼 
    package com.june.servlet;  
     
    import javax.servlet.http.HttpServlet;  
    import javax.servlet.http.HttpServletResponse;  
    import javax.servlet.http.HttpServletRequest;  
    import java.io.IOException;  
    import java.io.PrintWriter;  
    import javax.servlet.ServletException;  
     
    public class jqueryAjaxServer extends HttpServlet {  
         public jqueryAjaxServer(){  
             super();  
         }  
         public void doGet(HttpServletRequest request,HttpServletResponse response)  
         throws IOException ,ServletException {  
             response.setContentType("text/html;charset=utf-8");  
             PrintWriter out=response.getWriter();  
             String account=request.getParameter("account");  
             if("iamcrzay".equals(account)){  
                 out.print("Sorry,the user is exist");  
             }  
             else{  
                 out.print("Congratulation,this accont you can use!!!!");  
             }  
             out.close();  
         }  
         public void doPost(HttpServletRequest request,HttpServletResponse response)  
         throws IOException ,ServletException {  
             this.doGet(request, response);  
         }  

    package com.june.servlet;

    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpServletRequest;
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletException;

    public class jqueryAjaxServer extends HttpServlet {
         public jqueryAjaxServer(){
          super();
         }
         public void doGet(HttpServletRequest request,HttpServletResponse response)
         throws IOException ,ServletException {
          response.setContentType("text/html;charset=utf-8");
          PrintWriter out=response.getWriter();
          String account=request.getParameter("account");
          if("iamcrzay".equals(account)){
           out.print("Sorry,the user is exist");
          }
          else{
           out.print("Congratulation,this accont you can use!!!!");
          }
          out.close();
         }
         public void doPost(HttpServletRequest request,HttpServletResponse response)
         throws IOException ,ServletException {
          this.doGet(request, response);
         }
    }

     

    下面是WEB.XML
    Xml代碼 
    <?xml version="1.0" encoding="UTF-8"?> 
    <web-app version="2.5"   
        xmlns="    xmlns:xsi="    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
            <servlet> 
           <servlet-name>jqueryAjaxServer</servlet-name> 
           <servlet-class>com.june.servlet.jqueryAjaxServer</servlet-class> 
        </servlet> 
            <servlet-mapping> 
           <servlet-name>jqueryAjaxServer</servlet-name> 
           <url-pattern>/jqueryAjax</url-pattern> 
        </servlet-mapping> 
      <welcome-file-list> 
        <welcome-file>index.jsp</welcome-file> 
      </welcome-file-list> 
    </web-app> 

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5"
     xmlns="
     xmlns:xsi=" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      <servlet>
        <servlet-name>jqueryAjaxServer</servlet-name>
        <servlet-class>com.june.servlet.jqueryAjaxServer</servlet-class>
     </servlet>
            <servlet-mapping>
        <servlet-name>jqueryAjaxServer</servlet-name>
        <url-pattern>/jqueryAjax</url-pattern>
     </servlet-mapping>
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app>

     

    下面是Jsp頁面
    第一個(gè)是 jqueryAjax.jsp  本頁使用的是$.ajax()
    Html代碼 
    <%@ page language="java"  pageEncoding="utf-8"%> 
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    <html> 
      <head>    
        <title>jquery ajax</title>   
        <meta http-equiv="pragma" content="no-cache"> 
        <meta http-equiv="cache-control" content="no-cache"> 
        <meta http-equiv="expires" content="0">      
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
        <meta http-equiv="description" content="This is my page"> 
        <script src="js/jquery-1.2.6.js" type="text/javascript"></script> 
        <script language="javascript"> 
             $(function(){  
                   $('.sumbit').click(function(){  
                   if($('#account').val().length==0){  
                       $('.hint').text("用戶名不能位空").css({"background-color":"green"});   
                   }  
                   else{  
                   $.ajax({  
                    
    url:'jqueryAjax',  
                     data:{account:$('#account').val()},  
                     error:function(){  
                     alert("error occured!!!");  
                     },  
                     success:function(data){  
                      $('body').append("<div>"+data+"</div>").css("color","red");  
            
                     }  
                       
                   });}  
                   });  
                   });  
                       
             
                 
        </script> 
      </head> 
        
      <body> 
                    <h3 align="center">jquery AjaX</h3> 
                    <hr> 
                    <label>請輸入用戶名 :</label> 
                    <input id="account" name="account" type="text"> 
                    <input class="sumbit" type="button" value="檢測"> 
                    <div class="hint"> 
                    </div> 
      </body> 
    </html> 

    <%@ page language="java"  pageEncoding="utf-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head> 
        <title>jquery ajax</title>
     <meta http-equiv="pragma" content="no-cache">
     <meta http-equiv="cache-control" content="no-cache">
     <meta http-equiv="expires" content="0">   
     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
     <meta http-equiv="description" content="This is my page">
     <script src="js/jquery-1.2.6.js" type="text/javascript"></script>
     <script language="javascript">
          $(function(){
                $('.sumbit').click(function(){
                if($('#account').val().length==0){
                    $('.hint').text("用戶名不能位空").css({"background-color":"green"});
                }
                else{
                $.ajax({
                  url:'jqueryAjax',
                  data:{account:$('#account').val()},
                  error:function(){
                  alert("error occured!!!");
                  },
                  success:function(data){
                   $('body').append("<div>"+data+"</div>").css("color","red");
      
                  }
                 
                });}
                });
                });
                    
       
           
     </script>
      </head>
     
      <body>
                    <h3 align="center">jquery AjaX</h3>
                    <hr>
                    <label>請輸入用戶名 :</label>
                    <input id="account" name="account" type="text">
                    <input class="sumbit" type="button" value="檢測">
                    <div class="hint">
                    </div>
      </body>
    </html>

     

    第二個(gè)用的是  $.post()

    Html代碼 
    <%@ page language="java"  pageEncoding="utf-8"%> 
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    <html> 
      <head>    
        <title>jquery ajax</title>   
        <meta http-equiv="pragma" content="no-cache"> 
        <meta http-equiv="cache-control" content="no-cache"> 
        <meta http-equiv="expires" content="0">      
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
        <meta http-equiv="description" content="This is my page"> 
        <script src="js/jquery-1.2.6.js" type="text/javascript"></script> 
        <script language="javascript"> 
             $(function(){  
                 $('.sumbit').click(  
                  function(){  
                    if($('#account').val().length==0){  
                        $('.hint').text("The account is cant't be null").css({"color":"red","background-color":"yellow"});  
                    }  
                    else{  
                    $.post("jqueryAjax","account="+$('#account').val(),function(data){  
                       $('.hint').text(data).css({"color":"red","background-color":"yellow"});  
                    })  
                    }  
                 });  
             });             
        </script> 
      </head> 
        
      <body> 
                    <h3 align="center">jquery Ajax</h3> 
                    <hr> 
                    <label>請輸入用戶名 :</label> 
                    <input id="account" name="account" type="text"> 
                    <input class="sumbit" type="button" value="檢測"> 
                    <div class="hint"> 
                    </div> 
      </body> 
    </html> 

    <%@ page language="java"  pageEncoding="utf-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head> 
        <title>jquery ajax</title>
     <meta http-equiv="pragma" content="no-cache">
     <meta http-equiv="cache-control" content="no-cache">
     <meta http-equiv="expires" content="0">   
     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
     <meta http-equiv="description" content="This is my page">
     <script src="js/jquery-1.2.6.js" type="text/javascript"></script>
     <script language="javascript">
          $(function(){
              $('.sumbit').click(
               function(){
                 if($('#account').val().length==0){
                     $('.hint').text("The account is cant't be null").css({"color":"red","background-color":"yellow"});
                 }
                 else{
                 $.post("jqueryAjax","account="+$('#account').val(),function(data){
                    $('.hint').text(data).css({"color":"red","background-color":"yellow"});
                 })
                 }
              });
          });       
     </script>
      </head>
     
      <body>
                    <h3 align="center">jquery Ajax</h3>
                    <hr>
                    <label>請輸入用戶名 :</label>
                    <input id="account" name="account" type="text">
                    <input class="sumbit" type="button" value="檢測">
                    <div class="hint">
                    </div>
      </body>
    </html>

     

    第三個(gè)是用的$.get()

    Html代碼 
    <%@ page  pageEncoding="utf-8"%> 
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    <html> 
      <head>     
        <title>jquery get</title> 
          
        <meta http-equiv="pragma" content="no-cache"> 
        <meta http-equiv="cache-control" content="no-cache"> 
        <meta http-equiv="expires" content="0">      
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
        <meta http-equiv="description" content="This is my page"> 
        <script src="js/jquery-1.2.6.js" type="text/javascript"></script> 
        <script type="text/javascript"> 
             $(function(){  
                    $('.sumbit').click(function(){  
                          if($('#account').val().length==0){  
                             $('.hint').html("用戶名不能位空!!!").css({"color":"#ffoo11","background":"blue"});  
                          }  
                          else{  
                              $.get("jqueryAjax","account="+$('#account').val(),  
                                   function(data){  
                                    $('.hint').html(data).css({"color":"#ffoo11","background":"green"});  
                              });  
                          }  
                    });  
             });  
        </script> 
     
      </head> 
        
      <body> 
            <h3 align="center">jquery AjaX</h3> 
                    <hr> 
                    <label>請輸入用戶名 :</label> 
                    <input id="account" name="account" type="text"> 
                    <input class="sumbit" type="button" value="檢測"> 
                    <div class="hint"> 
                    </div> 
      </body> 
    </html> 

    主站蜘蛛池模板: 久久久无码精品亚洲日韩蜜桃| 亚洲av无码一区二区三区观看| 日本卡1卡2卡三卡免费| 亚洲精品欧洲精品| 又色又污又黄无遮挡的免费视| 中文字幕乱码免费看电影| 亚洲va在线va天堂va手机| 亚洲一区无码精品色| 日韩中文字幕精品免费一区| 免费无码国产在线观国内自拍中文字幕| 国产亚洲人成网站在线观看不卡| 成人毛片免费观看视频在线| 97在线免费观看视频| 亚洲av无一区二区三区| 亚洲AV日韩AV高潮无码专区| 国产成人精品免费视频软件| 99爱在线观看免费完整版| 瑟瑟网站免费网站入口| 亚洲国产成人无码av在线播放| 亚洲成a人片在线播放| 毛片免费视频观看| 免费成人高清在线视频| 国产亚洲福利精品一区二区| 亚洲国产精品久久久久秋霞影院| 国产午夜亚洲精品理论片不卡 | 九九精品免费视频| 青青操免费在线视频| 国产精品无码亚洲一区二区三区| 亚洲精品综合一二三区在线 | 久久精品国产亚洲综合色| 日本一线a视频免费观看| 亚洲精品免费在线视频| 在线涩涩免费观看国产精品| 国产精品亚洲一区二区无码| 亚洲真人无码永久在线观看| 精品无码一区二区三区亚洲桃色| 亚洲色欲久久久综合网东京热| 国产精品公开免费视频| 成人奭片免费观看| 日本三级2019在线观看免费| 1000部禁片黄的免费看|