2016-07-14 2 views
0

양식 로그인 (JSecurityCheck)을 사용하여 로그인 시스템을 만들고 있습니다. 사용자 이름과 암호는 MySQL 데이터베이스 내에 저장됩니다. 데이터베이스에 자격 증명으로 로그인하려고하면 오류 페이지가 표시됩니다. 나는 심지어 데이터베이스에 액세스 하는지를보고 싶지만 어떻게 확신 할 수는 없다. 여기 JSP가 데이터베이스에 연결되어 있는지 확인하는 방법은 무엇입니까?

은 (단지 중요한 물건) 관련 소스 코드입니다 :

web.xml :

<security-constraint> 
    <display-name>Security Constraint</display-name> 
    <web-resource-collection> 
     <web-resource-name>Protected Area</web-resource-name> 
     <url-pattern>/protected/*</url-pattern> 
     <http-method>DELETE</http-method> 
     <http-method>GET</http-method> 
     <http-method>POST</http-method> 
     <http-method>PUT</http-method> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name> manager </role-name> 
    </auth-constraint> 
    <user-data-constraint> 
     <transport-guarantee>NONE</transport-guarantee> 
    </user-data-constraint> 
</security-constraint> 

<!-- Default login configuration uses form-based authentication --> 
<login-config> 
    <auth-method>FORM</auth-method> 
    <realm-name>Example Form-Based Authentication Area</realm-name> 
    <form-login-config> 
     <form-login-page>/home.jsp</form-login-page> 
     <form-error-page>/error.jsp</form-error-page> 
    </form-login-config> 
</login-config> 
<security-role> 
    <description> An administrator </description> 
    <role-name> manager </role-name> 
</security-role> 

login.jsp :

<html> 
 
<head> 
 
<title>Login to Employee Services</title> 
 
<body bgcolor="white"> 
 
    <br /><br /> 
 
    <form method="POST" 
 
     action='<%=response.encodeURL("j_security_check")%>'> 
 
     <table border="1"> 
 
      <thead> 
 
       <tr> 
 
        <th colspan="2">Employee Services</th> 
 
       </tr> 
 
      </thead> 
 
      <tbody> 
 
       <tr> 
 
        <td>Employee Number</td> 
 
        <td><input type="text" name="j_username" required /></td> 
 
       </tr> 
 
       <tr> 
 
        <td>Password</td> 
 
        <td><input type="password" name="j_password" required /></td> 
 
       </tr> 
 
       <tr> 
 
        <td colspan="2" align="center"><input type="submit" 
 
         value="Log In" /> &nbsp;&nbsp; <input type="reset" value="Reset" /> 
 
        </td> 
 
       </tr> 
 
      </tbody> 
 
     </table> 
 
    </form> 
 
</body> 
 
</html>

server.xml (아파치 톰캣 디렉토리 아래) :

<Realm className="org.apache.catalina.realm.JDBCRealm" debug="99" 
     driverName="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/UserDB?user=root;password=root" 
     userTable="users" userNameCol="employeeNum" userCredCol="password" 
     userRoleTable="user_roles" roleNameCol="role" /> 

============================== 편집 ==== =============================

나는 조금 주위에 놀고 난 그냥 콘솔에서 확인할 수 있습니다 깨달았다. 이 코멘트/대답을 남겨주세요 연결되지 않는 이유 사람이보고, 그래서 만약

나는 영역에 너무 익숙하지입니다.

오류 :

SEVERE: Exception performing authentication 
java.sql.SQLException: com.mysql.jdbc.Driver 
at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:692) 
at org.apache.catalina.realm.JDBCRealm.authenticate(JDBCRealm.java:350) 
at org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:294) 
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:449) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) 
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) 
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
at java.lang.Thread.run(Unknown Source) 

Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 
at java.net.URLClassLoader.findClass(Unknown Source) 
at java.lang.ClassLoader.loadClass(Unknown Source) 
at java.lang.ClassLoader.loadClass(Unknown Source) 
at java.lang.Class.forName0(Native Method) 
at java.lang.Class.forName(Unknown Source) 
at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:688) 
... 15 more 

답변

0

당신은 톰캣 또는 응용 프로그램에 존재하는 MySQL의 드라이버 클래스가 없습니다. 당신은 폴더를 here에서 드라이버를 다운로드하고 "lib 디렉토리 $ CATALINA_HOME /"를에 배치 할 수 있습니다.

+0

도움 주셔서 감사합니다. 나는 드라이버를 다운로드했으나 창문을 사용하고 있기 때문에 Project/Web-Inf/lib에 넣었습니다. 그러나 오류는 여전히 거의 동일합니다. – NotAMonkey24

+0

@ NotAMonkey24 서버 자체가 드라이버에 액세스해야합니다. Tomcat의 lib 폴더에 넣으십시오. – Gimby

+0

@ 김비 감사합니다. – NotAMonkey24

관련 문제