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>
复制代码

 

posted @   dirgo  阅读(796)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话
点击右上角即可分享
微信分享提示