题目要求
编写JSP页面login1.jsp、server.jsp 和loginSuccessjsp.在页面login 1.jsp 中输入用户名和密码,单击“提交”按钮将输入的信息提交给页面server.jsp。在server.jsp页面中进行登录验证:如果输入正确(用户名为“zhangsan",密码为“123”, 提示“成功登录,3秒钟后进入loginSuccess.jsp页面”;如果输入不正确,重新定向到login 1.jsp 页面。运行login 1.jsp 页面。
页面运行效果如图所示:
登录页面login1.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=UTF-8">
<title>登录页面</title>
</head>
<body>
<form action="server.jsp">
姓名:<input type="text" name="userName" value="">
<br>
密码:<input type="password" name="pwd" value="">
<br>
<input type="submit" value="提交">
</form>
</body>
</html>
登录中……server.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=UTF-8">
<title>登录中……</title>
</head>
<body>
<%
String username=request.getParameter("userName");
String password=request.getParameter("pwd");
if("zhangsan".equals(username)&&"123".equals(password)){
out.print("成功登陆,3秒后进入loginSuccess.jsp页面");
response.setHeader("refresh", "3;url=loginSuccess.jsp");
}else{
out.print("账号或密码错误,2秒后回到login1.jsp页面");
response.setHeader("refresh", "2;url=login_1.jsp");
}
%>
</body>
</html>
loginSuccess.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=UTF-8">
<title>登陆成功</title>
</head>
<body>
<font color="green" align="center">欢迎张三登录成功!</font>
</body>
</html>