Ajax does not refresh the page in case of implementation of the user name to determine
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
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
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)
- Category: February 2009
- Related recommend
Comment
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. . ...
- 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
- 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 ]
Related Posts of Ajax does not refresh the page in case of implementation of the user name to determine call stored procedure
hibernate call stored procedure
Based on Spring's Hibernate Search full-text search function of sample (JDBC ...