Jquery ajax login verification implementation code

Source: Internet
Author: User

Use the jquery framework: Download jquery. js
Create a web project ajax;
Create a jslib folder under webRoot: specifically store js files;
Create an html/jsp page under webRoot:
Login.html Copy codeThe Code is as follows: <script type = "text/javascript" src = "jslib/jquery. js"> </script>
<Script type = "text/javascript" src = "jslib/verify. js"> </script>
</Head>
<Body>
<H1> user verification <! -- Form submission is not required in ajax -->
<! -- The name attribute is not required in the input tag. Only the id attribute is used. -->
<! -- Use the id attribute to use dom -->
<Input type = "text" id = "username"/> <br/>
<Input type = "button" value = "verify" onclick = "verify ()"/>
<! -- Div is empty to store the information returned by the server -->
<Div id = "result"> </div>
</Body>

Create a js file under jslib:
Verify. js;Copy codeThe Code is as follows: function verify ()
{
Var paramObj = encodeURI ($ ("# username"). val ()));
$. Get ("TestSvlt? Username = "+ paramObj, null, callback );
}
Function callback (data)
{
Var resultObj = $ ("# result ");
ResultObj.html (data );
}

Create a new servlet: AjaxLogin class; write it in the doGet MethodCopy codeThe Code is as follows: response. setContentType ("text/html; charset = UTF-8 ");
PrintWriter out = response. getWriter ();
String name = request. getParameter ("username ");
String username = URLDecoder. decode (name, "UTF-8 ");
System. out. println (username );
If (null = username | "". equals (username ))
{
Out. print ("username is not null ");
}
Else
{
If (! "Lej". equals (username ))
{
Out. print (username + "not existing ");
}
Else {
Out. print (username + "login successs ");
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.