題目要求
撰寫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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/159596.html
標籤:其他
上一篇:MySQL——Lock鎖
