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");
}
}