jsp内置对象作业1-用户登录

题目:编写一个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>

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值