• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlets and session...Do I need to?

 
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic