이것은 JSP 페이지 2 개 사이에서 값을 교환하는 첫 번째 시도이며 index.jsp 페이지에는 로그인 양식이 있으며 로그인에 실패하면 login.jsp 페이지는이 로그인의 유효성을 검사합니다 ,는 0의 값으로, 유효라는 매개 변수와 함께 index.jsp를로 리디렉션됩니다, 성공적인 경우, 값이 로그인입니다 index.jsp를 1다른 JSP 페이지에서 가져온 매개 변수를 사용할 수 없음
<%@page import="javax.enterprise.inject.spi.Bean"%>
<%@page import="myDatabase.Login"%> //this is class that I created
<%@page import="myDatabase.JavaDB"%> //this is a class that I created
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="indexCSS.css" />
<title>Chat</title>
</head>
<body>
<jsp:include page="login.jsp">
<jsp:param name="valid" value="1"/>
</jsp:include>
<% String valid = request.getParameter("valid");%>
<div class="mainPage">
<div id="header">
<div id="pageTitle">
Chat
</div>
</div>
<div id="loginBox">
<form name="login" action="login.jsp" method="POST">
<div id="loginItems">
<div id="loginTitle">
Log in
</div>
<hr style="color:green;">
<div style="margin-top:17px; overflow:hidden;">
<label for="id">
ID
</label>
<span id="idError" class="error">
<% if(valid.equals("0")) { %>is not valid<% } %>
</span>
<br>
<input class="inputText" type="text" name="id" value="" maxlength="10" autocomplete="off"/>
</div>
<div style="margin-top:17px; overflow:hidden;">
<label for="password">
Password
</label>
<span id="passwordError" class="error">
</span>
<br>
<input class="inputText" type="password" name="password" value="" maxlength="32" autocomplete="off"/>
</div>
<div style="margin-top:17px; overflow:hidden;">
<div>
Forgot your Password?
</div>
</div>
<div style="margin-top:17px; position:relative; overflow:hidden">
<input class="inputButton" type="submit" value="Log in" name="loginButton" />
</div>
</div>
</form>
</div>
</div>
</body>
</html>
될 것입니다 .jsp
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<jsp:useBean id="loginBean" scope="session" class="myDatabase.Login" />
<jsp:setProperty name="loginBean" property="id" />
<jsp:setProperty name="loginBean" property="password" />
<%
JavaDB myJavaDB=new JavaDB();
myJavaDB.Connect("IULChat","iul","iul");
if(myJavaDB.isConnected()==true){
//response.sendRedirect("index.jsp?a=2");
Login myLogin = new Login(loginBean.getId(),loginBean.getPassword());
myLogin.setConn(myJavaDB.getMyConnection());
myLogin.login(); loginBean.setId(0); loginBean.setPassword("");
if(myLogin.isValid()==true)
{
response.sendRedirect("index.jsp?valid=1");
}
else
{
response.sendRedirect("index.jsp?valid=0");
}
}
else
out.println("no");
%>
</body>
</html>
프로젝트를 실행할 때이 오류가 발생합니다. 내가
<span id="idError" class="error">
<% if(valid.equals("0")) { %>is not valid<% } %>
</span>
정말 고마워요! –