How to do simple login in Ajax local refresh application
This article shows you how to log in in the local refresh application of Ajax. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Don't say a word, just give it to the code. I believe all you need is code rather than a pile of nonsense.
1.java Code:
The code is as follows:
Package tt
Import java.io.IOException
Import java.io.PrintWriter
Import javax.servlet.ServletException
Import javax.servlet.http.HttpServlet
Import javax.servlet.http.HttpServletRequest
Import javax.servlet.http.HttpServletResponse
Public class TestA extends HttpServlet {
Private static final long serialVersionUID =-7999241892841130740L
Protected void doGet (HttpServletRequest request
HttpServletResponse response) throws ServletException, IOException {
Request.setCharacterEncoding ("utf-8")
String name = request.getParameter ("name")
Response.setContentType ("text/xml; charset=utf-8")
Response.setHeader ("Cache-Control", "no-cache")
PrintWriter out = response.getWriter ()
Out.println ("")
If (name.equals ("yangjinde")) {
Out.println ("+" Sorry, the name 'yangjinde' is already registered "+")
} else {
Out.println ("+" can register with "+")
}
Out.println ("")
Out.close ()
}
}
2.jsp Code:
The copy code is as follows:
My JSP 'index.jsp' starting page
/ / set a variable
Var XMLHttpReq=false
/ / create a XMLHttpRequest object
Function createXMLHttpRequest () {
If (window.XMLHttpRequest) {/ / Mozilla
XMLHttpReq=new XMLHttpRequest ()
}
Else if (window.ActiveXObject) {
Try {
XMLHttpReq=new ActiveXObject ("Msxml2.XMLHTTP")
} catch (e) {
Try {
XMLHttpReq=new ActiveXObject ("Microsoft.XMLHTTP")
} catch (e) {}
}
}
}
/ / send request function
Function send (url) {
CreateXMLHttpRequest ()
XMLHttpReq.open ("GET", url,true)
XMLHttpReq.onreadystatechange=proce; / / specify the function of the response
XMLHttpReq.send (null); / / send request
}
Function proce () {
If (XMLHttpReq.readyState==4) {/ / object status
If (XMLHttpReq.status==200) {/ / the information has been returned successfully. Start processing the information.
Var res=XMLHttpReq.responseXML.getElementsByTagName ("content") [0] .firstChild.data
Window.alert (res)
Document.getElementById ("data") [xss_clean] = res
Document.getElementById ("name") .value = res
} else {
Window.alert ("Sorry, the requested page has an exception")
}
}
}
/ / Authentication
Function check () {
Var name=document.getElementById ("name"). Value
If (name== "") {
Alert ("Please enter content")
Return false
}
Else {
Send ('login?name='+name)
}
}
Name:
I will change later!
3.xml profile Code:
The code is as follows:
Login
Tt.TestA
Login
/ login
Index.jsp
The above content is how to simply login in the Ajax local refresh application. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.