题目:编写一个jsp程序,实现用户登录,当用户输入的用户名或密码错误时,将页面重定向到错误提示也,并在该页面显示30秒后,自动返回到用户登录页面.

1.用户登录页面



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 <form name = "form1" action="denglu.jsp">
11
12 用户名:
13 <input type = "text" name = "user"><br>
14 密码:
15 <input type = "password" name = "pw"><br>
16 <input type = "submit" name = "bt" value = "提交">
17
18 </form>
19
20 </body>
21 </html>


2,登录处理页面



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 <%
11 //正确的用户名密码
12 String user1 = "123";
13 String pw1 = "123";
14 //获取输入的用户名密码
15 String user = request.getParameter("user");
16 String pw = request.getParameter("pw");
17 //判断用户名密码是否正确
18 if(user.equals(user1) & pw.equals(pw1))
19 {
20 out.print("登录成功");
21 }
22 else
23 {
24 response.sendRedirect("error.jsp");
25 }
26 %>
27 </body>
28 </html>


3,错误提示页



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 用户名或密码错误,请稍后重试.
11 <%
12 //30秒后重定向至登录页
13 response.setHeader("refresh","30;URL = index.jsp");
14 %>
15 </body>
16 </html>