js| Tips
Static login interface design login.htm, the code is as follows:
<title> System Login </title>
<style type= "Text/css" ....
<!--
. Style1 {...} {
font-size:18px;
Font-weight:bold;
}
. Style2 {...} {FONT-SIZE:24PX}
. style5 {...} {FONT-SIZE:16PX}
-->
</style>
<body bgcolor= "papayawhip" width= "height=" >
<center>
<table border= "2" bordercolor= "Black" bgcolor= "LightGreen" >
<tbody>
<tr>
<td><div align= "center" class= "Style1 style2" > System Login
</div></td>
</tr>
<form action= "login.jsp" method= "POST" >
<tr>
<TD height= ><span class= "style5" > User name </span> <input type= "text" name= "UID" maxlength= "2 0 "style=" width:150 "></td></tr><br>
<tr>
<td><span class= "style5" > Password </span> <input type= "password" name= "upwd" maxlength= "style=" width:150 "></td></tr><br>
<center>
<tr><td><div align= "center" >
<input type= "Submit" value= "Login" >
<input type= "reset" value= "Cancel" >
</div></td></tr>
</center>
</form>
</tbody>
</table>
</center>
</body>
To submit the information entered by the Logged-in user to the LOGIN.JSP page model processing, here for convenience, do not perform the database access operation, directly using sky2098 as the login username and password, but in practice is to read from the database, the JSP page code implementation is as follows:
<%...@ page contenttype= "text/html;charset=gb2312"%>
<% ...
if (Request.getparameter ("UID"). Equals ("sky2098") &&request.getparameter ("Upwd"). Equals ("sky2098")) {
Session.setattribute ("Login", "OK");
Session.setmaxinactiveinterval (-1);
%>
<jsp:forward page= "main.jsp"/>
<% ...
}else{
Out.println ("User name or password input error!") ");
}
%>
If the login is successful, then set login value is OK, submit to the next verification page, then enter the main.jsp page, otherwise, if you enter the username and password is not legitimate to print error messages, main.jsp page code as follows:
<%...@ page contenttype= "text/html;charset=gb2312"%>
<%...@ include file= "checkvalid.jsp"%>
<title>~welcome to my homepage~</title>
<body>
<center>
~welcome to my homepage~
</center>
</body>
This page uses the <% @ include file= "checkvalid.jsp"%> contains a JSP page checkvalid.jsp to verify the legality of the input information:
<% ...
if (Session.getattribute ("login") ==null| |! Session.getattribute ("Login"). Equals ("OK")) {
Response.sendredirect ("login.htm");
}
%>
If the input information is incorrect, return to the login page and re-enter the login information.
Test the login feature.
Start the Tomcat server and type the URL in the IE Address bar as:
Http://localhost:8080/sky2098/login-Advanced/login.htm