jquery Ajax Login Authentication Implementation code _jquery

Source: Internet
Author: User
Using the jquery framework: Download jquery.js
Create a new Web project Ajax;
Create a new Jslib folder under WebRoot: Specially store JS file;
Create a new html/jsp page under WebRoot:
Login.html
Copy Code code as follows:

<script type = "Text/javascript" src = "jslib/jquery.js" ></script>
<script type = "Text/javascript" src = "jslib/verify.js" ></script>
<body>
<!--Ajax can be used without the submit--> of form forms
<!--input label does not need to use the Name property, just use the id attribute on the line-->
<!--ID attribute is used to use dom-->
<input type = "text" id = "username"/><br/>
<input type = "button" value = "checksum" onclick = "verify ()"/>
<!--div is empty to store information returned by the server-->
<div id = "Result" ></div>
</body>

Create a new JS file under Jslib:
Verify.js;
Copy Code code as follows:

function Verify ()
{
var Paramobj=encodeuri (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 in the Doget method
Copy Code code 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.