欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

index.jsp页面实现用户登录,deal.jsp页面实现用户登录处理,当用户名或密码输入错误时,重定向至error,jsp页面

程序员文章站 2022-07-03 21:35:54
用户登录页面<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>用户登录

用户登录页面

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户登录</title>
</head>
<body>
<form name="form1" method="post" action="deal.jsp">
<div align="center">
用户名:<input type="text" name="name" value=""><br>
</div>
<div align="center">
密 &nbsp&nbsp&nbsp码:<input type="text" name="password" value=""><br>
</div>
<div align="center">
<input type="submit" name="Submit" value="登录">
</div>
</form>
</body>
</html>

用户登录处理页面

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户登录处理</title>
</head>
<body>
<%
String name=request.getParameter("name");
String password=request.getParameter("password");
if(name.equals("张三")&&password.equals("123456")){
    out.print("<script language='javascript'>alert('登录成功!');window.location.href='index.jsp';</script>");
}
else{
    response.sendRedirect("error.jsp");
}
%>
</body>
</html>

错误提示页面

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
response.setHeader("refresh","30;URL=index.jsp");
//30秒后,自动返回用户登录页面
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>错误提示页面</title>
</head>
<body>
用户名或密码出错,请重新输入
</body>
</html>

本文地址:https://blog.csdn.net/qq_46048366/article/details/107488478