File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets and session...Do I need to?

 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am right now working on an application which has some 20 JSPs and 5 servlets. It is an appln where user logs into the system in two different modes and perform the operations. The back End is Oracle.

My concern now is, is it necessary to maintain a session. Though it may sound absurd, i am quite new to developing applications and this is my first one.

If so, how to get the session persisting for the entire application?

Kindly help me in this regard.

Thanks in advance.....

Cheers,
Swamy
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can maintain the session yourself if you really want to. otherwise the servlet will maintain its own session HttpSession anyway.

you can get that session like this:

request.getSession(true)

or session id like this:

request.getSession(true).getId()
[ September 13, 2004: Message edited by: adeel ansari ]
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Adeel.

I shall try this out and get back to you. Any ways, it would be great if you can expand a bit on Why do we go for a session, when servlet can maintain its own? How long that session is active?

Is there any difference between the user maintained and the servlet maintained session?

Thanks a lot in advance.

Cheers,
Swamy
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1 - this is the optional element in web.xml by which we can tell our container how long a session will exists.

<session-config>
<session-timeout>60</session-timeout>
</session-config>

2 - by saying "we maintain session" i mean, incase we want to do somthing on session creation or destruction, like maintain logs of session in some file or in DB. then we have to do it for ourselves by implementing HttpSessionListener. this class is not found in the previous release of servlet specification. so we used to use HttpSessionBindingListener for this kind of implementation.
 
Sham Grandhe
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai adeeel
This is sham kumar from bangalore. our chat on the topic is helping me, thank u, can you plz just specify which version of servlet the Listener are present

thank you
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we have HttpSessionListener in servlet 2.4, previous version i am not sure. we can use it with tomcat 5.0.

as i said for previous version we can go for HttpSessionBindingListener. i haven't tried this but hope it would work.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpSessionListener since Servlets 2.3; HttpSessionBindingListener since Servlets 2.0. HttpSessionBindingListener notifies when attributes are bound or unbound to/from the session, rather than when the session itself is created/destroyed. I guess you could contrive this pre-2.3 to perform the same functionality as the newer HttpSessionListener.

Jules
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic