0
我們創建了一個登錄頁面,用戶可以在其中輸入用戶名和密碼。當點擊登錄時,我們將用戶名+密碼發送到名爲「validateLogin」的JSP文件。成功登錄時加載新頁面「JSP java」
我可以在點擊「登錄」按鈕時使用一些關於如何加載新頁面的建議。
到目前爲止我的代碼的「validateLogin」
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.io.*,java.util.*" %>
<!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 uid, pass;
uid = request.getParameter("userid");
pass = request.getParameter("password");
if ("mk123".equals(uid) && "1234".equals(pass))
{
// sæt attributten "logget ind" i sessionen
session.setAttribute("logged in", "yes");
out.println("You have succesfully logged in<br>");
// New location to be redirected
String site = new String("http://localhost:8080/CDIO3_-_Gruppe17/ScaleWeb.jsp");
response.setHeader("Location", site);
}
else
{
// fjern attributten "logget ind" fra sessionen
session.removeAttribute("logged in");
out.println("Wrong userid or password.<br>");
}
%>
Try enter
<a href="ScaleWeb.jsp">the protected page </a> or go back to
<a href="Login.jsp">page </a>.
</body>
</html>
的我試圖在if語句創造的東西,但它真的這麼想的正常工作。