File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes HttpSession-object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpSession-object" Watch "HttpSession-object" New topic
Author

HttpSession-object

Frederik Rambout
Greenhorn

Joined: Sep 29, 2005
Posts: 2
Could I get the current user session-object and save it to an Oracle database when I write my own servlet?

Or should I write my "own" HttpSession-class?

When a session invalidates I should be able to "restore" the session the user had.

The only thing though, how would I know which stored object would be the one that belonged to that user...

Thanks
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
Save the username with this object for later identification.


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Why?

If you want the session to last longer, make the expirey value larger. If you want to persist data for a user, attach it to the user so that you can load it when the user logs in.

I'm generally against trying to recreate the session funnctionality in web containers. It is too tied into the rest of the functionality to do in a stable manner.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Why you want to persist user session into database?

You can do that by storing not just the session but a session with the user name and timestamp. You can store some more info if you want to.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by David O'Meara:
If you want to persist data for a user, attach it to the user so that you can load it when the user logs in.


Cent percent agreement.
Frederik Rambout
Greenhorn

Joined: Sep 29, 2005
Posts: 2
This is the problem :

We have web-applications containing folders.
For example : the folder "fr" contains the French site, de folder "nl" the Dutch site.
Also, some folders are used by both websites, they are also located at the same location "nl" and "fr" folders are.

Every jsp includes a header and a footer. The jsp's that are only used by that exact website include directly the right header and footer.
When a user enters the homepage, he has to choose between "go to french" of "go to dutch". So at that point we set the language.

But those folders, containing jsp's that are used by both websites have a problem. So we let them include 2 jsp's : site_header.jsp and site_footer.jsp. Those 2 files check the session, retrieve the language that was set when the user entered the homepage and load the exact footer and header.

So : when a user waits too long, and he continues to browse, and he enters a jsp that includes the site_header and footer jsp's, he won't see any header and footers because the session was invalidated and no language was set.

We could extend the session time-out, but this is not our main goal.
We could use cookies, but we won't use persistent cookies.
URL-rewriting is not an option as a lot of the code is dynamically generated by xml and xsl and it would take a lot of work to adapt every single url.

That's why I thought maybe I could store the session into a database.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Thats why we said, "you need the data stored in session, not the session". Yes you can persist that particular attribute or all attributes along with the user-name.

I hope you just would like to show the message in his/her preferred language. The messaage could be like, "Your session has been expired". Because after session expiry there is no means to allow him/her work. If you want them to work even when session has been expired, then you had better set session-timeout to -1.
 
 
subject: HttpSession-object