Koerr
Koerr

Reputation: 15723

Why session object is changed(JSP,servlet)?

I set a attribute in JSP session:

session.setAttribute("test","123");

and I print session Id and session HashCode every minute:

out.println("sessionID:"+session.getId()+" sessionHashCode:"+session.hashCode());

I get the below result:

time:00:05
sessionID:awZ5kgzGNZf4 sessionHashCode:4861179

time:00:06
sessionID:awZ5kgzGNZf4 sessionHashCode:4861179

..

time:03:41
sessionID:awZ5kgzGNZf4 sessionHashCode:708977

..

time:03:46
sessionID:awZ5kgzGNZf4 sessionHashCode:5376793

in time 03:41 and 03:46, the session object changed,

when I using:

session.getAttribute("test");

return null

Why is there this problem? how to fit it?

thank for help :)

(I using resin_2.1.4 web server)


thanks for Jigar Joshi - org.life.java help,

I try to print session properties :

time: 2011-03-11/04:21
sessionID:aJ5KCTx6gi-6 sessionHashCode:31002685
[session]creationTime:2011-03-11/03:32 lastAccessedTime:2011-03-11/04:21 maxInactiveInterval:1800

time: 2011-03-11/04:22
sessionID:aJ5KCTx6gi-6 sessionHashCode:5278202
[session]creationTime:2011-03-11/04:22 lastAccessedTime:2011-03-11/04:22 maxInactiveInterval:1800

I don't think because my resin session conf.

Upvotes: 2

Views: 1526

Answers (2)

Rado
Rado

Reputation: 436

How do you retrieve the session object to print its properties every minute?

I print session Id and session HashCode every minute

Upvotes: 1

Jigar Joshi
Jigar Joshi

Reputation: 240860

It seems the case of session timeout.

Check your web.xml

<session-config>
  <session-timeout>30</session-timeout> 
</session-config>

After timeout idel session gets destroyed.

Upvotes: 3

Related Questions