当前位置:
文档之家› (完整版)JSP登陆页面代码
(完整版)JSP登陆页面代码
response.sendRedirect("login.htm");
}
%>
如果输入信息有误,则回到登录页面,重新输入登录信息。
注册页面:reg.jsp
请输入您的注册信息:
<table>
<form action="/user/Reg" method="post" name="regform" onsubmit="return regconfirm();">
session.setAttribute("login","ok");
session.setMaxInactiveInterval(-1);
%>
<jsp:forward page="main.jsp"/>
<%
}else{
out.println("用户名或密码输入错误!");
}
%>
如果登录成功,则设定login的值为ok,提交到下一步验证页面,则进入main.jsp页面,否则,如果输入的用户名和密码不合法就打印错误信息,main.jsp页面代码如下:
<tr><td>密码:</td><td><input type="password" name="user_pwd" id="user_pwd" size="20" maxlength=10 onBlur="checkPWD();">*可以包含字母数字(区分大小写),6-10位</td>
<tr><td>系别:</td><td><select name="user_xibie" id="user_xibie">
35.
36. </tbody>
37. </table>
38. </center>
39. </body>
40. </html>
<html>
<head>
<title>系统登录</title>
<style type="text/css">...
<!--ze: 18px;
font-weight: bold;
}
.style2 {...}{font-size: 24px}
.style5 {...}{font-size: 16px}
-->
</style>
</head>
<body bgcolor="papayawhip" width="300" height="300">
<center>
26. <tr>
27. <td><span class="style5">密 码</span> <input type="password" name="upwd" maxlength="20" style="width:150"></td></tr><br>
28. <center>
</table>
登录页面login.jsp
<form action="/Login" method="post">
<table>
<tr><td>请输入账号:</td><td><input type="text" name="login_id" size="20"></td>
<tr><td>请输入密码:</td><td><input type="password" name="login_pwd" size="10"></td>
<tr><td>ID:</td><td><input type="text" name="user_id" id="user_id" size="20" maxlength=10 onBlur="checkID();">*可以包含字母数字,6-10位</td>
<tr><td>姓名:</td><td><input type="text" name="user_name" size="20" ></td>
22. </tr>
23. <form action="login.jsp" method="post">
24. <tr>
25. <td height="28"><span class="style5">用户名</span> <input type="text" name="uid" maxlength="20" style="width:150"></td></tr><br>
静态的登录界面的设计login.htm,代码如下:
Html代码
1. <html>
2. <head>
3. <title>系统登录</title>
4. <style type="text/css">...
5. <!--
6. .style1 {...}{
7. font-size: 18px;
8. font-weight: bold;
29. <tr><td><div align="center">
30. <input type="submit" value="登录" >
31. <input type="reset" value="取消">
32. </div></td></tr>
33. </center>
34. </form>
Java代码
1. <%@ page contentType="text/html;charset=GB2312"%>
2. <%@ include file="checkvalid.jsp" %>
3. <html>
4. <head>
5. <title>~WELCOME TO MY HOMEPAGE~</title>
Java代码
1. <%
2. if(session.getAttribute("login")==null||!session.getAttribute("login").equals("ok")){
3. response.sendRedirect("login.htm");
4. }
5. %>
<%
if(session.getAttribute("login")==null||!session.getAttribute("login").equals("ok")){
9. }
10. .style2 {...}{font-size: 24px}
11. .style5 {...}{font-size: 16px}
12. -->
13. </style>
14. </head>
15. <body bgcolor="papayawhip" width="300" height="300">
<center>
<tr><td><div align="center">
<input type="submit" value="登录" >
<input type="reset" value="取消">
</div></td></tr>
</center>
</form>
</tbody>