Tomcat jdbc连接" nullpointerexception"对于领域

时间:2015-06-12 03:29:16

标签: tomcat servlets jdbc

我试图在servlet中使用域来保证安全性。

这是WEB-IF / web.xml的领域部分

<security-constraint>
    <web-resource-collection>
        <web-resource-name>X</web-resource-name>
        <url-pattern>/karbar/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>karbar</role-name>
    </auth-constraint>
</security-constraint>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Y</web-resource-name>
        <url-pattern>/modir/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>modir</role-name>
    </auth-constraint>
</security-constraint>
<security-role>
    <role-name>modir</role-name>
</security-role>
<security-role>
    <role-name>karbar</role-name>
</security-role>

这是tomcat的server.xml中的realm标记:

<Realm
            className="org.apache.catalina.realm.JDBCRealm"
            driverName="oracle.jdbc.driver.OracleDriver"
            conncetionURL="jdbc:oracle:thin:@localhost:1521:orcl"
                connectionName="kian"
                connectionPassword="myjava123"
                userTable="users"
                userNameCol="name"
                userCredCol="password"
                userRoleTable="roles"
                roleNameCol="user_role"
   />

我还在classes12.jar

中复制了apache-tomcat-7.0.19\lib

问题是现在网络服务器因此错误而断开连接:

INFO: Starting Servlet Engine: Apache Tomcat/7.0.19
java.lang.NullPointerException
   at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:358)
at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:711)
at org.apache.catalina.realm.JDBCRealm.startInternal(JDBCRealm.java:782)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1026)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:727)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.startup.Catalina.start(Catalina.java:621)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)
Disconnected from server

1 个答案:

答案 0 :(得分:1)

对不起伙计们。我认为这是intelJ 12.0或tomcat中的一个错误! 只是检查jdbc驱动程序,我运行了另一个项目,我知道应该运行正常。它确实如此,然后我回到上面的项目,它也工作得很好!

我不知道发生了什么。为什么会出现问题以及为什么突然之间就会消失。