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

sponsored links
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 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 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



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





>> 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

  • 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 ]

  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

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

  • Dynamic loading JS script four kinds of methods

    To achieve dynamic loading JS script has four kinds of methods: 1, direct document.write <script language="javascript"> document.write ( "<script src='test.js'> <\ / script>"); </ script> 2, dynamic scri

  • Hibernate primary key strategy-sequence

    Today, the use of hibernate in the company encountered a troublesome problem, the use of hibernate when the primary key generation strategy set sequence, but always reported in the implementation could not get next sequence value of the error, then o ...

  • hibernate call stored procedure

    hibernate call stored procedure

  • Based on Spring's Hibernate Search full-text search function of sample

    Database: Oracle 9i JDBC Driver: OJDBC14 Development Environment: Eclipse-JEE Spring version: Spring 2.0.6 Hibernate version: Hibernate Core 3.2.5/Hibernate Annotation 3.3.0/Hibernate Validator 3.0.0/Hibernate Search 3.0.0 Beta4 / / jdbc.properties (JDBC

  • Hibernate pessimistic locking mechanism for locking and optimistic locking

    hibernate lock mechanism 1. Pessimistic lock It refers to the modification of data by outsiders hold a conservative attitude. The assumption that at any time access to data, may also have another client to access the same data, in order to maintain t ...

  • Nan-Jing 5: When IBatis.Hibernate mixed affairs, pay attention to your SQL

    [Problem] Now, in the development of the so-called multi-storey JavaEE applications, data persistence layer is always essential, and "Automatic" of ORM - Hibernate, and "all-manual-type" of SqlMap - IBatis, equivalent data are Per ...

  • hibernate to use the principle of

    The use of hibernate, implementation of data persistence. Has the following several processes. One configuration database connection information. Hibernate.config 2 configuration mapping. 3 use: the use of the process are the following steps: 3.1: Ge ...

  • Based on JDBC, JPA Annotation achieve simple CRUD Generic Dao

    The origin of ideas are pretty long history of reasons: [Use iBATIS history] The use of iBATIS has been a long time, the system is to use the CRUD template tool to generate the code, although there are tools to generate, but looked at a lot of CRUD the Sq

  • The level Hibernate cache

    Hibernate cache level: (1) a cache is very short and the session life cycle consistent, also known as session-level cache-level cache or transaction-level cache (2) Ways of Supporting level cache: get (); load (); iterator (); only entity object cach ...

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries