데이터베이스에 연결할 수 있지만 로그인을 시도하는 동안 잘못된 데이터가 전달되면 동일한 index.jsp 파일을 다시 호출 할 수 없습니다.
데이터베이스에 연결하면 index.jsp 파일이 표시되고 [email protected] 1234 데이터와 함께 이메일과 비밀번호를 입력합니다.이 데이터는 내 데이터베이스에 있으므로 menu.jsp 페이지로 리디렉션됩니다. 잘못된 데이터를 넣었습니다 : [email protected] 12 그것은 또한 저를 menu.jsp로 리디렉션합니다. 이제 다음 오류가 발생합니다.
Mar 30, 2014 12:14:14 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/Cap] threw exception [/index.jsp
(line: 33, column: 41) quote symbol expected] with root cause
org.apache.jasper.JasperException: /index.jsp (line: 33, column: 41) quote symbol expected
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
..........
index.jsp의 33 행은
<jsp:getProperty name="login" property="value" />
getEmail 및 getPasword가 예상대로 null 만 반환하지 않습니다.
<jsp:useBean id="member" class="StaffMember" scope="session"/>
<jsp:setProperty name="member" property="*"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Welcome</title>
</head>
<body bgcolor="lightblue">
<font size=4>
<center>
</center>
<form method=post> <hr><br>
<center>
<b>LOGIN</b><p>
<input type=text name=email value= email value = member.setEmail(email)> <p>
<input type=text name=password value=password value = member.setPassword(password)> <p>
<input type=submit value="Submit">
<jsp:getProperty name="login" property="value" />
<c:if value = "false" action="index.jsp"></c:if>
<c:if value = "true" action="menu.jsp"></c:if>
</center>
<img src="<%=request.getContextPath()%>/images/ndnuLogo.jpg"/>
<br><hr>
</form>
</font>
</body>
</html>
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.FormParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import com.sun.jersey.api.view.Viewable;
public class LoginServiceImplem implements LoginService{
private Connection connection;
private Statement statement;
private boolean value; //used to check if user that login is on the list of user available to
//test
public LoginServiceImplem() throws SQLException{
connection = null;
statement = null;
value = false;
StaffMember sm = new StaffMember();
value = login(sm.getEmail(), sm.getPassword());
}
public boolean getValue() {
return value;
}
public void setValue(boolean value) {
this.value = value;
}
public boolean login(String email, String password) throws SQLException{
System.out.println(email + " " + password);
String query = "SELECT * FROM cap.member WHERE Email= '" + email + "'"
+ " AND Password = '" + password + "'";
ResultSet rs = null;
try {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//builds a connection and statement
connection = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/" +
"cap", "root", "");
System.out.println("After connection");
statement = connection.createStatement();
System.out.println("After statement");
rs = statement.executeQuery(query);
System.out.println("After rs");
//if the statement returns something
if(rs.next()){
//and email and password match the database information, return true
return(email.equals(rs.getString("Email"))
&& password.equals(rs.getString("Password")));
}
}finally {
//close all connections
DbUtil.close(rs);
DbUtil.close(statement);
DbUtil.close(connection);
}return false;
}
}
public class StaffMember {
private String emailAddress;
private String password;
public StaffMember() {
emailAddress = "[email protected]";
password = "1234";
}
/* The setEmail method sets the employee's email */
public void setEmail(String email) {
emailAddress = email;
}
public void setPassword(String pword){
password = pword;
}
/* The getEmail method gets the employee's email. */
public String getEmail() {
return emailAddress;
}
public String getPassword(){
return password;
}
}
내가 아무것도 놓친 것이 없다면 Java 코드에 아래 줄이 없기 때문에 "적합한 드라이버를 찾을 수 없음"오류가 발생한다고 생각합니다. 내가 빠진 것이 있으면 알려주세요.
Class.forName("com.mysql.jdbc.Driver");
"LoginServiceImplem"클래스에 추가 할 수 있습니다. 다음과 같은 정적 블록에서
static {
Class.forName("com.mysql.jdbc.Driver");
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다