简体   繁体   English

Javaobject“连接”不适用于禁用的Cookies

[英]Javaobject “Connection” does not work with disabled Cookies

i am having a Problem with disabled Cookies. 我有禁用Cookies的问题。 i am Having a page where a User logs in with his User account. 我有一个页面,其中有一个用户使用其用户帐户登录。 The connection itself is saved in the session, if the login was sucessfull. 如果登录成功,连接本身将保存在会话中。

request.getSession().setAttribute("connection"  , connection);

the Object DBConnection, named connection in the Session, is an Object, which has got a static Connection con Object 对象DBConnection(在会话中称为连接)是一个对象,它具有一个静态连接con对象

protected static Connection con = null;

when the User logs in, the Connections gets established with 当用户登录时,使用以下命令建立连接

con = DriverManager.getConnection(url, this.user, this.password);

This also works with dectivated cookies. 这也适用于低迷的Cookie。 if was checking the Connection and the con Object i want to save with a System.out.println. 如果正在检查连接和我要使用System.out.println.保存的con对象System.out.println.

System.out.println(("DBConnection == null: " + connection == null));
System.out.println("Connection" connection.getCon());
//result ->
//DBConnection == null: false
//oracle.jdbc.driver.T4CConnection@15d51e5

So the Login was sucessfull. 因此登录成功。 now the User leave this side and go to some other information Pages due to a button. 现在,由于有一个按钮,用户离开这一面并转到其他信息页面。 in Here i need this connection again and i am getting it in a Servlet. 在这里,我再次需要此连接,并且正在Servlet中获取它。

DBConnection connection = (DBConnection)request.getSession().getAttribute("connection");

with the Same System.out.println as before it gives the same result as before, when cookies are enabled. 启用cookie时,使用与以前相同的System.out.println获得与以前相同的结果。 When cookies are disabled, it throws an Exception with this results: 禁用cookie时,它会引发Exception并显示以下结果:

DBConnection == null: false
java.lang.NullPointerException

So now my Question. 所以现在我的问题。 Why does my connection break, when i have my cookies disabled? 禁用cookie时,为什么连接断开? In my mind cookies don´t have anything to deal with the connection Object, or any other Object beeing saved within a JSP? 在我看来,Cookie没有任何处理连接对象或JSP中保存的其他对象的东西? The connection Object throwing the Nullpointer is the Object in the Package java.sql.Connection; 抛出Nullpointer的连接对象是包java.sql.Connection;的对象java.sql.Connection;

This problem is related on how does the application or web servers store the session id on the cliente side: they use cookies for this. 此问题与应用程序或Web服务器如何在客户端存储会话ID有关:它们为此使用cookie。

On how to enable session binding for disabled cookies clients, you could check this related question on this very same site: How can i do sessions in java if some one disables cookies in my browser? 关于如何为禁用的cookie客户端启用会话绑定,您可以在同一站点上检查以下相关问题: 如果有人禁用了浏览器中的cookie,如何在java中进行会话?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM