Business description
The user enters the user name password login on the login.jsp page:
If the user name is Xingoo, the password is 123, then jump to the successful interface login_success.jsp, and display the user login name;
If the user name password is incorrect, jump to the failed interface login_failure.jspand prompt to return to the login screen.
login.jsp Code
<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="Utf-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>User Login</title></Head><Body> <H1>User Login</H1> <HR> <formname= "RegForm"Action= "dologin.jsp"Method= "POST"> <Table> <TR> <TD>Username</TD> <TD><inputtype= "text"name= "username"/></TD> </TR> <TR> <TD>Password</TD> <TD><inputtype= "Password"name= "Password"/></TD> </TR> <TR> <TDcolspan= "2"><inputtype= "Submit"value= "Submit"/></TD> </TR> </Table> </form></Body></HTML>
DOLOGIN.JSP Processing Code
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding= "Utf-8"%><%String username= ""; String Password= ""; Request.setcharacterencoding ("Utf-8"); Username= Request.getparameter ("username"); Password= Request.getparameter ("Password"); if("Xingoo". Equals (username) && "123". Equals (password)) {Session.setattribute ("Loginuser", username); Request.getrequestdispatcher ("Login_success.jsp"). Forward (Request,response); }Else{response.sendredirect ("Login_failure.jsp"); }%>
LOGIN_SUCCESS.JSP User Login Successful interface
<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="Utf-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>User Login</title></Head><Body> <H1>User Login</H1> <HR>you are welcome!<%=Session.getattribute ("Loginuser") %></Body></HTML>
LOGIN_FAILURE.JSP User Login Failure interface
<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="Utf-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>User Login</title></Head><Body> <H1>User Login</H1> <HR>Login failed!<ahref= "login.jsp">Back to Login</a></Body></HTML>
JSP Implementation User Login Example