婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > jquery訪問(wèn)servlet并返回?cái)?shù)據(jù)到頁(yè)面的方法

jquery訪問(wèn)servlet并返回?cái)?shù)據(jù)到頁(yè)面的方法

熱門標(biāo)簽:百靈鳥 上海浦東百度地圖標(biāo)注中心注冊(cè) 老虎郵局地圖標(biāo)注點(diǎn) 襄陽(yáng)外呼系統(tǒng)接口 青海醫(yī)療智能外呼系統(tǒng)怎么樣 外呼系統(tǒng)獲取客戶手機(jī)號(hào) 科智聯(lián)智能電銷機(jī)器人 徐州電銷卡外呼系統(tǒng)供應(yīng)商 目標(biāo)三維地圖標(biāo)注

本文實(shí)例講述了jquery訪問(wèn)servlet并返回?cái)?shù)據(jù)到頁(yè)面的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

1. servlet:AjaxServlet.java如下:

復(fù)制代碼 代碼如下:
package com.panlong.servlet; 

import java.io.IOException; 
import java.io.PrintWriter; 
import java.net.URLDecoder; 

import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

public class AjaxServlet extends HttpServlet { 
    private static final long serialVersionUID = 1L; 
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
            throws ServletException, IOException { 
        Integer total = (Integer) req.getSession().getAttribute("total"); 
        int temp = 0; 
        if(total == null ){ 
            temp = 1; 
        }else{ 
            temp = total.intValue() + 1; 
        } 
    req.getSession().setAttribute("total",temp); 
        try { 
            //1.取參數(shù) 
            resp.setContentType("text/html;charset=GBK"); 
            PrintWriter out = resp.getWriter(); 
            String old = req.getParameter("name"); 
            //2.檢查參數(shù)是否有問(wèn)題 
            //String name = new String(old.getBytes("iso8859-1"),"UTF-8"); 
            String name = URLDecoder.decode(old,"UTF-8"); 
            if("".equals(old) || old == null){ 
                out.println("用戶名必須輸入"); 
            }else{ 
                if("liling".equals(name)){ 
                    out.println("恭喜登錄成功"); 
                    return; 
                }else{ 
                    out.println("該用戶名未注冊(cè),您可以注冊(cè)["+name+"]這個(gè)用戶名"+temp); 
                } 
            } 
        } catch (Exception e) { 
            // TODO Auto-generated catch block 
            e.printStackTrace(); 
        } 
        //3.檢驗(yàn)操作 
    } 
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) 
            throws ServletException, IOException { 
        doGet(req, resp); 
    } 
}

2. verify.js如下:

復(fù)制代碼 代碼如下:
function verify(){ 
    //解決中文亂碼問(wèn)題的方法1,頁(yè)面端發(fā)出的數(shù)據(jù)作一次encodeURI,服務(wù)端使用new String(old.getBytes("iso8859-1"),"UTF-8"); 
    //解決中文亂碼問(wèn)題的方法2,頁(yè)面端發(fā)出的數(shù)據(jù)作兩次encodeURI,服務(wù)端使用String name = URLDecoder.decode(old,"UTF-8"); 
    var url = "servlet/AjaxServlet?name="+encodeURI(encodeURI($("#userName").val())); 
    url = convertURL(url); 
    $.get(url,null,function(data){ 
        $("#result").html(data); 
    }); 

//給url地址增加時(shí)間蒫,難過(guò)瀏覽器,不讀取緩存 
function convertURL(url){ 
    //獲取時(shí)間戳 
    var timstamp = (new Date()).valueOf(); 
    //將時(shí)間戳信息拼接到url上 
    if(url.indexOf("?") >=0){ 
        url = url + "t=" + timst 
    }else{ 
        url = url + "?t=" + timst 
    } 
    return url; 
}

3. 前臺(tái)頁(yè)面如下:

復(fù)制代碼 代碼如下:
!DOCTYPE html> 
html> 
  head> 
    title>AJAX實(shí)例/title> 
    meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
    meta http-equiv="description" content="this is my page"> 
    meta http-equiv="content-type" content="text/html; charset=GBK"> 
    script type="text/javascript" src="js/verify.js">/script> 
    script type="text/javascript" src="js/jquery.js">/script> 
    !--link rel="stylesheet" type="text/css" href="./styles.css">--> 
  /head> 
  body> 
        font color="blue" size="2">請(qǐng)輸入用戶名:/font>  
         input type="text" id="userName" />font color="red" size="2">span id="result" >*/span>/font>br/>br/> 
         !-- div id="result">/div> --> 
          input type="submit" name="提交" value="提交"  onclick="verify()"/> 
  /body>
/html>

希望本文所述對(duì)大家的Ajax程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:
  • 利用JQuery和Servlet實(shí)現(xiàn)跨域提交請(qǐng)求示例分享
  • 實(shí)例解讀Ajax與servlet交互的方法
  • js調(diào)用后臺(tái)servlet方法實(shí)例
  • java中servlet實(shí)現(xiàn)登錄驗(yàn)證的方法
  • 基于HttpServletRequest 相關(guān)常用方法的應(yīng)用
  • 基于HttpServletResponse 相關(guān)常用方法的應(yīng)用
  • java servlet 幾種頁(yè)面跳轉(zhuǎn)的方法
  • java中Servlet處理亂碼的方法
  • 訪問(wèn)JSP文件或者Servlet文件時(shí)提示下載的解決方法

標(biāo)簽:荊州 商洛 佛山 揭陽(yáng) 辛集 股票 紅河 咸寧

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《jquery訪問(wèn)servlet并返回?cái)?shù)據(jù)到頁(yè)面的方法》,本文關(guān)鍵詞  jquery,訪問(wèn),servlet,并,返回,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《jquery訪問(wèn)servlet并返回?cái)?shù)據(jù)到頁(yè)面的方法》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于jquery訪問(wèn)servlet并返回?cái)?shù)據(jù)到頁(yè)面的方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 五峰| 青冈县| 太保市| 辉县市| 夏河县| 遂平县| 黄陵县| 依安县| 太仆寺旗| 衡南县| 长乐市| 鄱阳县| 全椒县| 原平市| 区。| 永城市| 新干县| 滨州市| 固阳县| 云和县| 南澳县| 清涧县| 轮台县| 龙江县| 台南县| 荔浦县| 梁山县| 山西省| 台南县| 邓州市| 泸水县| 同仁县| 阿拉善盟| 云和县| 武冈市| 乐山市| 民和| 巴青县| 通州市| 龙岩市| 犍为县|