用户登录界面

1) 设计一个用户登录页面、一个用户登录信息验证页面、一个用户登录成功页面、一个错误处理页面、两个受保护页面以及若干被静态包含的页面片段。

2) 用户登录信息包括学号和密码,学号是本人学号并且密码正确则登录成功,自动跳转到用户登录成功页面;如果出现异常(例如学号没有输入、密码没有输入、学号或密码不正确等),则抛出异常,由错误处理页面处理。

3) 登录成功页面,显示登录用户信息,并显示受保护页面访问的列表。

4) 一个受保护页面介绍本人的简历;一个受保护页面介绍本人的业余爱好。两个页面必须登录后访问,如果没有登录,则跳转到登录页面。

5) 静态包含的页面片段包括三个:一个是统一的头部信息;一个是统一的尾部信息;一个是验证用户是否登录的代码。

Login.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>用户登录页面</title>
 8 <style>
 9 body{
10 background-color:#DDD;
11 }
12 #main{text-align:center;font-size:18px;padding: 100px;    background-color:#FFDAB9; 300px;margin: 3px auto;border:1px solid}
13 </style>
14 </head>
15 <body>
16 <div  id="main">
17     <form action="do_login.jsp" method="post">
18             学号:<input type="text" name="username"><br><br>
19             密码:<input type="password" name="password"><br><br>
20     <input type="submit" value="登录">
21     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
22     <input type="submit" value="重置"></form>
23     </div>
24 </body>
25 </html>

do_login.jsp:登录判断

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3     <%@page errorPage="error.jsp"%>
 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 5 <html>
 6 <head>
 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 8 <title>登录验证</title>
 9 <style>
10 body{
11 background-color:#FFDAB9;
12 }
13 </style>
14 </head>
15 <body>
16 <%
17    String name =(String)request.getParameter("username");
18    String pwd =(String)request.getParameter("password");
19     if(name=="")
20           throw new Exception("学号必须填写!");
21     else if(pwd=="")
22           throw new Exception("密码必须填写!");
23     else if(!name.equals("143401010107")||!pwd.equals("143401010107"))
24           throw new Exception("学号或密码输入错误!"); 
25     else if(name!=null && pwd!=null){
26        if(name.equals("143401010107")&&pwd.equals("143401010107")){
27            session.setAttribute("u", name);
28            session.setAttribute("flag", pwd);
29            response.sendRedirect("showInfo.jsp");
30        }
31    }
32 %>
33 </body>
34 </html>

showInfo.jsp:显示登录信息

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 7 <title>个人信息</title>
 8 <style>
 9 body{
10 background-color:#FFDAB9;
11 }
12 </style>
13 </head>
14 <body>
15 <%
16 String flag = (String)session.getAttribute("flag");
17 if(flag!=null){
18     response.sendRedirect("select.jsp");
19 }else{
20     out.print("您还没有登录");
21     response.sendRedirect("login.jsp");
22 }
23 %>
24 </body>
25 </html>

select.jsp:

<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>选择</title>
<style>
body{
background-color:#FFDAB9;
}
#main{text-align:center;}
</style>
</head>
<body id="main">
<h1>恭喜你,登录成功!</h1>
<p>个人信息:</p><br>
<p>姓名:***</p><br>
<p>班级:***</p><br>
<p>学号:***</p><br>
<a href="resume.jsp"><font size="5">个人简历</font></a><br><br>
<a href="hobbit.jsp"><font size="5">个人爱好</font></a>
</body>
</html>

resume.jsp:

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>个人简历</title>
 8 <style>
 9 #top{text-align:center;font-size:12px;}
10 #main{text-align:center;font-size:18px;}
11 #bottom{text-align:center;font-size:12px;}
12 body{
13 background-color:#FFDAB9;
14 }
15 </style>
16 </head>
17 <body>
18 <div id="top"><%@include file="top.jsp" %></div>
19 <div id="main">
20 <h1>本人简历</h1>
21 <p>姓名:***</p>
22 <p>性别:女</p>
23 <p>籍贯:****</p>
24 <p>联系方式:*********</p>
25 <p>......</p>
26 </div>
27 <div id="bottom"><%@include file="bottom.jsp" %></div>
28 </body>
29 </html>

hobbit.jsp:

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>个人爱好</title>
 8 <style>
 9 #top{text-align:center;font-size:12px;}
10 #main{text-align:center;font-size:18px;}
11 #bottom{text-align:center;font-size:12px;}
12 body{
13 background-color:#FFDAB9;
14 }
15 </style>
16 </head>
17 <body>
18 <div id="top"><%@include file="top.jsp" %></div>
19 <div id="main">
20 <h1>本人爱好</h1>
21 <p>喜欢跑步</p>
22 <p>喜欢听情歌</p>
23 <p>喜欢吃零食</p>
24 <p>喜欢看电影</p>
25 <p>喜欢睡大觉</p>
26 <p>......</p>
27 </div>
28 <div id="bottom"><%@include file="bottom.jsp" %></div>
29 </body>
30 </html>

top.jsp:

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>头部内容</title>
 8 </head>
 9 <body>
10 <p><font size="2" color="blue">This page is made by 143401010107</font></p>
11 <hr>
12 </body>
13 </html>

bottom.jsp:

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>尾部内容</title>
 8 </head>
 9 <body>
10 <hr>
11 <p>
12 <font size="2" color="red">CopyRight@copy2017.<br>有任何问题请联系<a href="mail:****@qq.com">**</a>
13 </font></p>
14 </body>
15 </html>

原文地址:https://www.cnblogs.com/Lia-633/p/7802640.html