Java – tomcat, which uses the user session storage of JDBC store, and immediately timeout the session

I tried to store user session data in a database I've followed some articles and Tomcat documentation on how to do this

I am now using Tomcat 7 and PostgreSQL and can confirm that inserts is working, but there are still problems Tomcat inserts the user session into the database and immediately deletes it:

From my Tomcat tomcat7 / conf / context Fragment of XML:

...
<Manager className="org.apache.catalina.session.PersistentManager"           
        maxIdleBackup="1"
        minIdleSwap="0"
        maxIdleSwap="0"
        processExpiresFrequency="1"
        saveOnRestart='true'
        >

        <Store className="org.apache.catalina.session.JDBCStore"                
                connectionURL="jdbc:postgresql://localhost:5432/tomcat?user=[USER]&amp;password=[PASSWORD]"
                driverName="org.postgresql.Driver"
                sessionAppCol="app_name"
                sessionDataCol="session_data"
                sessionIdCol="session_id"
                sessionLastAccessedCol="last_access"
                sessionMaxInactiveCol="max_inactive"
                sessionTable="tomcat_sessions"
                sessionValidCol="valid_session" 
                />
</Manager>
...

I also added this to my tomcat7 / conf / Catalina properties:

...
org.apache.catalina.session.StandardSession.ACTIVITY_CHECK=true
org.apache.catalina.STRICT_SERVLET_COMPLIANCE=true
...

I have a PostgreSQL JDBC connector in tomcat7 / lib

Changes I've tried:

> Tomcat 6 > Tomcat 7 > MysqL > Postgresql

I'm still conf / logging The following contents have been added to properties. I hope I can debug further:

...
org.apache.catalina.session.PersistentManager.level = ALL
org.apache.catalina.session.PersistentManager.useParentHandlers = true
org.apache.catalina.session.level = ALL
org.apache.catalina.session.useParentHandlers = true
...

Table mode is

+---------------+--------------+------+-----+---------+-------+
| Field         | Type         | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| session_id    | varchar(100) | NO   | PRI | NULL    |       |
| valid_session | char(1)      | NO   |     | NULL    |       |
| max_inactive  | int(32)      | NO   |     | NULL    |       |
| last_access   | int(64)      | NO   |     | NULL    |       |
| app_name      | varchar(255) | YES  | MUL | NULL    |       |
| session_data  | mediumblob   | YES  |     | NULL    |       |
+---------------+--------------+------+-----+---------+-------+

Tomcat log display:

Jun 27,2013 2:16:33 PM org.apache.catalina.session.PersistentManagerBase processExpires
FINE: Start expire sessions PersistentManager at 1372338993228 sessioncount 1
Jun 27,2013 2:16:33 PM org.apache.catalina.session.PersistentManagerBase processMaxIdleSwaps
FINE: Swapping session 22115A5964B70168B1752D5415DAD31C to Store,idle for 36 seconds
Jun 27,2013 2:16:33 PM org.apache.catalina.session.PersistentManagerBase processExpires
FINE: End expire sessions PersistentManager processingTime 168 expired sessions: 0

PostgreSQL log display:

2013-06-27 14:16:33 IST LOG:  execute <unnamed>: INSERT INTO tomcat_sessions (session_id,app_name,session_data,valid_session,max_inactive,last_access) VALUES ($1,$2,$3,$4,$5,$6)
2013-06-27 14:16:33 IST DETAIL:  parameters: $1 = '22115A5964B70168B1752D5415DAD31C',$2 = '/Catalina/localhost/[SERVLET_NAME]',$3 = '\xaced...f72',$4 = '1',$5 = '1800',$6 = '1372338956718'
2013-06-27 14:16:33 IST LOG:  execute <unnamed>: SELECT session_id FROM tomcat_sessions WHERE app_name = $1
2013-06-27 14:16:33 IST DETAIL:  parameters: $1 = '/Catalina/localhost/[SERVLET_NAME]'
2013-06-27 14:16:33 IST LOG:  execute <unnamed>: SELECT session_id,session_data FROM tomcat_sessions WHERE session_id = $1 AND app_name = $2
2013-06-27 14:16:33 IST DETAIL:  parameters: $1 = '22115A5964B70168B1752D5415DAD31C',$2 = '/Catalina/localhost/[SERVLET_NAME]'
2013-06-27 14:16:33 IST LOG:  execute <unnamed>: DELETE FROM tomcat_sessions WHERE session_id = $1  AND app_name = $2
2013-06-27 14:16:33 IST DETAIL:  parameters: $1 = '22115A5964B70168B1752D5415DAD31C',$2 = '/Catalina/localhost/[SERVLET_NAME]'

Thank you in advance

Solution

I switched to the MySQL database and used bigint instead of int (64) It solved this problem for me

I don't know why... Love to be a programmer!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>