login.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
</head>
<body>
<h1>Login</h1>
<form method="post" action="server.jsp">
<input type="text" placeholder="用户名" name="u"></input>
<input type="password" placeholder="密码" name="p"></input>
<button class="but" type="submit">登录</button>
</form>
<p>测试账号:admin<br>测试密码:123
</p>
</body>
</html>
server.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>验证ing</title>
</head>
<body>
<%
String u=request.getParameter("u");
String p=request.getParameter("p");
if("admin".equals(u)&&"123".equals(p)){
response.sendRedirect("loginSuccess.jsp");
}
else{
response.sendRedirect("login.jsp");
}
%>
</body>
</html>
loginsuccess.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login Success</title>
</head>
<body>
<h1>恭喜您,登陆成功!</h1>
</body>
</html>
网页截图