1、登陆界面代码
// Login.jsp
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="Check.jsp" method="setAtrribute">
<input type="text" name="username"/><br>
<input type="password" name="pwd"/><br>
<input type="submit" value="submit"/>
<input type="reset" value="reset"/>
</form>
</body>
</html>
2、检查界面代码
// Check.jsp
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
//
String name=request.getParameter("username");
session.setAttribute("username1", name);
String password=request.getParameter("pwd");
%>
<%
if(name.equals("Lewis")&&password.equals("123")){
%><jsp:forward page="Success.jsp"></jsp:forward>
<%
}else{
%>
<jsp:forward page="Error.jsp"></jsp:forward>
<%
}
%>
</body>
</html>
3、成功界面代码
//Success.jsp
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
//String name=request.getParameter("username");
String name=(String)session.getAttribute("username1");
%>
欢迎,<%=name%>登录成功!
</body>
</html>
4、失败界面代码
//Error.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
错误的用户名或密码
<%
request.setCharacterEncoding("UTF-8");
//String name=request.getParameter("username");
String name=(String)session.getAttribute("username1");
//response.setHeader("refresh","3;url=Login.jsp"); %>
<a href="Login.jsp">重新登录</a>
</body>
</html>
5、测试结果
设置了正确的登陆账号和密码分别为:Lewis、123,账号密码正确跳转到登陆成功界面,输出“欢迎Lewis用户登录成功!”,反之,跳转到登陆失败界面,可选择重新登录,也可以选择设置3秒钟后自动跳转回登录界面。