سؤال

i need to user JDBC persistance for managing server session. and now i need to turn session value (saved in wl_session_values) into a real object. bellow i write my code :

try {
String userName = "root";
String password = "****";
String url = "jdbc:mysql://localhost:3306/test";
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);

PreparedStatement pstmt = null;
String query = "select * from wl_servlet_sessions";
pstmt = conn.prepareStatement(query);
ResultSet resultSet = pstmt.executeQuery();

while(resultSet.next()){
    System.out.println(resultSet.getString("wl_id"));

    Blob blob = resultSet.getBlob("wl_session_values");
    InputStream in = blob.getBinaryStream();
    ObjectInputStream ois = new ObjectInputStream(in);

    Hashtable<Object, Object> hash = (Hashtable)ois.readObject();
        for(Map.Entry<Object, Object> newHash : hash.entrySet()){
        System.out.println("Key : " + newHash.getKey().toString());
        System.out.println("Value : " + newHash.getValue().toString());
    }
}

} catch (Exception e) {
    e.printStackTrace();
} finally {
    if (conn != null) {
    try {
        conn.close();
    } catch (Exception e) { e.printStackTrace(); }
}

but when i try to deserialize the result, but i always get java.io.StreamCorruptedException: invalid stream header: 73720013.

thanks for any help.

هل كانت مفيدة؟

المحلول

Those are private APIs, so I would stay away.

You may solve your problem implementing your HttpSessionListener like in this example.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top