Ajax does not refresh the page in case of implementation of the user name to determine

Today, under the ajax implementation saw the sign box, javaeye before the implementation of a log in box is also estimated using ajax implementation. It can not refresh the page to verify the user name or verification code is correct applications. First of all we need tools are as follows: 1.intellij idea 8.1 download address http://download-ln.jetbrains.com/idea/idea-8.1.exe 2.jquery http://jqueryjs.googlecode.com/files/jquery-1.3.2. js it is some function, through which a new request to the server. so for the page we just call the button's onclick. 3.firefox thunder: / / QUFodHRwOi8vd3d3LjExOS54ZG93bnMuY29tL3VwbG9hZEZpbGUvMjAwOS0yL01vemlsbGEgRmlyZWZveC5yYXJaWg == This is a green version of the browser, it can js call to make very clear, simplified, and we also need to download the firebug. download the following address: http://releases.mozilla.org/pub/mozilla.org/addons/1843/firebug-1.3.2-fx. xpi. (installation method is very simple, as long as the above, drag it to firefox will prompt installation, after installation, click restart firefox browser you can, f12 shortcut keys it could be released. well, after the introduction of development tools, we ajax begin to bring our new surprise you. for previous page Jump to compare, we do a traditional page Jump. First of all install intelliJ, this would not have said, after the installation of new construction. our new PreServlet set up a class, are as follows: public class PreServletextends HttpServlet (protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException (try (System.out.println ( "call doGet"); response.setContentType ( "text / html ; charset = GB2312 "); PrintWriter out = response.getWriter (); String old = request.getParameter (" name "); if (old == null | | old.length () == 0) (out.println ( "User name should not be empty r");) else (String name = new String (old.getBytes ( "ISO8859-1")); if (name.equals ( "wangxingkui")) (out.println ( "User Name [ "+ name +"] already exists, please use other user name ");) else (out.println (" user name [ "+ name +"] not yet exist, you can register to use the user name ");)) out . println ( "
Check back page ");) catch (Exception e) (e.printStackTrace ();)) protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException (System.out.println (" call doPost "); doGet (request, response);)) END Servlet set up, we need to web.xml configured And PreServlet PreServlet PreServlet / PreServlet And we set up a page to display the Jump. Preindex.html the establishment of a new "http://www.w3.org/TR/html4/loose.dtd"> Check the user whether the services exist examples
This allows us to run what works can be seen on the traditional test results, it will jump to another page, and indicate the success of log. This time we have to click back to return to the Login page. With the traditional log in page Different of, ajax there is no need for refresh, or skip to another page, it will call a function in jQuery to request the server, which put the current page directly back to the user. until the server response to come back, it is only part of refresh. usually the call are jQuery's html (data) function below began to talk about building this example is as follows. We also create a new Servlet named AJAXServlet. as follows: public class AJAXServletextends HttpServlet (@ Override protected void doGet (HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException (try (System.out.println ( "int AJAXServer doGet"); httpServletResponse.setContentType ( "text / html; charset = utf-8"); PrintWriter out = httpServletResponse.getWriter (); Integer inte = (Integer) httpServletRequest. getSession (). getAttribute ( "total"); int temp = 0; if (inte == null) (temp = 1;) else (temp = inte.intValue () + 1;) httpServletRequest.getSession (). setAttribute ( "total", temp); String old = httpServletRequest.getParameter ( "name"); / / String name = new String (old.getBytes ( "iso8859-1"), "UTF-8"); if (old == null | | old.length () == 0) (out.println ( "User name should not be empty");) else (String name = URLDecoder.decode (old, "UTF-8"); if (name.equals ( "wangxingkui")) (out.println ( "user name [" + name + "] already exists, please use other user name," + temp);) else (out.println ( "user name [" + name + "] have not yet exist, you can register to use the user name," + temp);))) catch (Exception e) (e.printStackTrace ();)) @ Override protected void doPost (HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException (doGet (httpServletRequest, httpServletResponse);)) After set up, we need to configure the same under the web.xml. Ibid. Next, we need to create a ajaxindex.html "http://www.w3.org/TR/html4/loose.dtd"> itcast.cn actual ajax username check Username itcast.cn check ajax examples, please enter your user name

We here adopt onclick call it verify (), this method will call verify.js Lane, so we also need to import in the web under jquery-1.3.2.js and set up verify.js document. Verify.js documents are as follows: function verify () (var obj = $ ( "# userName"); var userName = obj.val (); / / the text box data sent to the Services section of servlet $ get ( "AJAXServlet? name =" + userName , null, callback, "GET");) / / callback function data are back-end data services ... Services client are at out.print ("..."); function callback (data) (/ / put The data obtained is displayed in the page var obj = $ ( "# result"); obj.html (data);) ok, js Ways Lane has also been set up well, we can debug interface of the next. attachment are related to the source Code:

  • 15:38
  • Browser (4)
  • Comments (0)
  • Category: February 2009
  • Related recommend
Comments
Comment

Ajax does not refresh the page in case of implementation of the user name to determine

Departed buy knife

  • View: 6333 times
  • Gender:
  • From: Xiamen
  • Details book
Search this blog
Recent visitors

dlboy

robot150

xueqingli

yuantong

>> More Visitors

Blog Categories
  • All blog (51)
  • February 2009 (7)
  • November 2008 (1)
  • J2SE (22)
  • J2ME (0)
  • J2EE (0)
  • Living (9)
  • SQL (2)
  • J2SE UI (2)
Other classification
  • My Favorites (1)
  • My Forum Posts (39)
  • Me the essence of a good paste (0)
Recently joined the circle of
  • JBoss SEAM
Archive
  • 2009-02 (14)
  • 2009-01 (1)
  • 2008-12 (2)
  • More archives ...
Latest Comments
  • Of Hashtable with HashMap
    If coupled with concurrent discussions can be just fine. . http://www.javae ...
    - By jiyanliang
  • Motorola A1200 day playing QQ ...
    Departed buy knife king_108 wrote A1200 wrote the LINUX system you use does not also line, ...
    - By QuakeWang
  • Motorola A1200 day playing QQ ...
    ha ha wrote webeasymail bought my cell phone the first day, not carried out 2 hours, no more than 50 yuan ...
    - By Walker to buy a knife
  • Motorola A1200 day playing QQ ...
    Haha bought my cell phone the first day, not carried out 2 hours, no more than 50 yuan ~ Khan ~ I'll go monthly
    - By webeasymail
  • Motorola A1200 day playing QQ ...
    A1200 wrote king_108 the LINUX system you use does not also line, speed is not that special ...
    - By Walker to buy a knife
Comments list
  • Motorola A1200 playing QQ day spent ten me a few ... ...
  • When China's education system would improve it.
  • Rockets, how in the end you had?
  • Thunderbolt java version download tool
  • Kung Bo Game
  • [What is RSS?]

Statement: JavaEye article copyright belong to the author, are protected by law. Without the written permission of the author may not be reproduced. If the consent of the author are reproduced, it is necessary to identify the article hyperlink form original source and authors.
© 2003 -2009 JavaEye.com. All rights reserved. Shanghai jiong resistant computer software Co., Ltd. [ ICP 05023328 ]

分类:AJAX 时间:2009-03-10 人气:1354
分享到:
blog comments powered by Disqus

相关文章

  • Servlet Implementation of the difference between Page Jump 2010-08-31

    Jump on the Servlet page has several ways of understanding the confused, and today has an online search to find again the better, write it down, take a look at the future. Servlet page jump in two parts, one occurred in the Servlet, one in the JSP, t

  • Fourteen common Java development tools, and its characteristics (transfer) 2010-03-29

    1, JDK (Java Development Kit) Java Development Kit From the novice point of view, using JDK develop Java programs can quickly understand the program, the relationship between the various parts of the code will help to understand Java object-oriented

  • java web development page Jump to forward the request 2009-06-21

    In the development of WEB system, we will face such a situation, a page of information processed, and some other pages dealing with the need to continue to address, this time there will be two options is to use the page jump, or in forwarding the req

  • Eclipse plug-ins to use Ruby Development Tools 2009-09-09

    Eclipse plug-ins to use Ruby Development Tools Document options Send as an e-mail this page Tomcat Application Development Download IBM open-source J2EE application server, WAS CE new version V1.1 Level: Intermediate Neal Ford ( neal.ford @ gmail.com

  • Ten essential Linux development environment development tools / Linux development tools Daquan / Linux Web Development Tools 2010-08-04

    Ten essential Linux development environment development tools / Linux development tools Daquan / Linux Web Development Tools 2009-03-26 10:14 Keywords: LINUX tool development environment for programming software Articles from http://www.lupaworld.com

  • JAVA development tools to use Eclipse (entry papers become the leader of education )---- 2010-08-16

    About ui Education http://www.neweredu.com/ Java development in the field present various integrated development environment (IDE) shows the situation a hundred flowers blossom, from Borland's JBuilder, to IBM's Visual Age for Java, WebSphere Studio,

  • jQuery development tools and plug-ins 2011-01-06

    1.Dreamweaver I believe everyone was familiar Dreamweaver, Dreamweaver is to create Web sites and applications of the professional tools. It visual layout tools, application development features and code editing support together, its powerful, so all

  • Five outstanding under the Linux open-source development tools 2009-06-11

    Linux is an excellent development environment, but without good development tools as a weapon, the environmental benefits you give will be greatly reduced. Fortunately, there is a lot of use of Linux and open source development tools for you to choos

  • Large collection of Web development tools 2009-07-01

    Author: Klaus Komenda , Translation: butwho English original: Collection of Web Developer Tools, per Browser Original found: Translation made-Collection of Web Developer Tools for major browsers Chinese translation: Large collection of Web developmen

  • Js page Jump (change) 2010-04-19

    Common function toUrl(ul){ if("" == ul || null==ul){ alert(" Thanks for the concern "); }else{ window.open(ul);// This is a new window // window.location.href=ul;// This is directly on the current page jump } return; } Other online: (w

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.412 (s). 13 q(s)