permaculture playing cards*
The moose likes Servlets and the fly likes Session time out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session time out " Watch "Session time out " New topic
Author

Session time out

Lynn Zhang
Greenhorn

Joined: Jun 04, 2004
Posts: 18
I have a question sounds like interesting: Say you have a web sites containing several applications App1, App2, App3. We need App1 session time out 20 minutes, App2 time out 40 minutes, and App3 time out 5 minutes. Is there a way even possible to do it?

Thanks.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Sure. This value can be configured in each web application's web.xml using the session-timeout element.
Lynn Zhang
Greenhorn

Joined: Jun 04, 2004
Posts: 18
Maybe I was not clear, I meant that all apps just is under one website and they just have one shared web.xml. Or put this way, you have a web application app1, then you put a link on app1 linking to app2, and you put another link on app1 to link to app3, but all these app1, app2 and app3 are just one web application. In this case can we still define the session time out for each of app1,app2,app3?
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
So your problem is that you want to maintain 3 different sessions for the apps that are actually a part of the same web application?
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
If they are part of the same war then they are not considered to be separate web applications. They are just different parts of the same web application.

Regardless, if your needs aren't met by configuration in the web.xml you can always set session timeout programatically by calling HttpSession.setMaxInactiveInterval(). It takes timeout value in terms of seconds (versus web.xml which is in terms of minutes).
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
BTW, this post is really in the wrong forum. Servlets would be more appropriate for this type of discussion so I am moving it there...
Lynn Zhang
Greenhorn

Joined: Jun 04, 2004
Posts: 18
To answer karthik Guru's question, yes.

To comment Chris Mathews's suggestion to use HttpSession.setMaxInactiveInterval(). This is not OK because this sets
all the session to be the same time out. So I still need a way to set time out for different part of the same web application. I thought if there is a way to set session object time out, maybe it solves the issue. We can set all session objects in app1 to 20 minutes and 40 for those session objects in app2 and 5 for those session objects in app3, but this sounds crazy, not sure even there is a way to set the time out for a session object.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Originally posted by Larry Zhang:
This is not OK because this sets
all the session to be the same time out. So I still need a way to set time out for different part of the same web application. I thought if there is a way to set session object time out, maybe it solves the issue. We can set all session objects in app1 to 20 minutes and 40 for those session objects in app2 and 5 for those session objects in app3, but this sounds crazy, not sure even there is a way to set the time out for a session object.

What you are suggesting is not technically possible or logically feasible. The HttpSession shared across all of your "apps" since everything is part of a single web application. Therefore, if you set the timeout for one "app" then, by definition, it will be set for all "apps" in that web application.

What you seem to want is separate HttpSessions for each "app". This can only be achieved by properly separating out your "apps" into separate web applications.
Lynn Zhang
Greenhorn

Joined: Jun 04, 2004
Posts: 18
Maybe your suggestion is the only way to achieve my goals. In doing so ( separating these apps into different ones ), do I need to separate the codes such as framework, utilities into different applications? If I do, I think the solution is not practical. Do we have a way to write a separate web.xml for separate part of web apps? Thanks Chris.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
You wouldn't separate the framework and utilities into separate wars but you would separate them into separate jars. These jars would then be reused by each of your web applications.

What about that solution is not practical? It is a common practice, in fact it is a best practice. How else do you manage reusable code throughout an organization? If you say "cut and paste" I am going to go to wherever you are and slap you...
[ June 10, 2004: Message edited by: Chris Mathews ]
Lynn Zhang
Greenhorn

Joined: Jun 04, 2004
Posts: 18
Thanks for your insights which are the best as far as I know, however I still have some hesitates:

Let me draw a small picture to describe my situation. (we are using WebSphere, WSAD development tool).

MyProject
Java Source
- Framework_folder
- utilites_folder
- App1_folder
- App2_folder
- App3_folder
Web Content
- jsp_folder
- jsps_for_App1
- jsps_for_App2
- jsps_for_App3
- html_folder
- image_folder
-WEB-INF
- classes
- lib
web.xml

First of all, all my framework and utilities classes will be compiled and put into Web Content/WEB-INF/classes - this is a WebSphere setting. These framework and utilities are frequently changed due to enhancement, it is not convenient to put them into jars. An addition issue, we are using App1 as a starting point and set session objects here and we want these session objects to be available in App2 and App3. If we separate App3 to be a different .war, it is easy for session objects set in App1 to be available in App3?
Rene Smith
Greenhorn

Joined: Jun 10, 2004
Posts: 21
If you are going to be using sessions set by app1 in app2 then why are you going to want them to timeout at different times? I'm confused?
Lynn Zhang
Greenhorn

Joined: Jun 04, 2004
Posts: 18
Simply put, think about App1 sets "user" session object, App2(very private data like salary display pages) needs session time out 5 minutes, but App2 ( having a very long text field filling page, taking 2 hours to finish typing) needs an 1 hour time out. Both App1 and App2 need "user" session object. However, we need a different time out.
Rishi Tandon
Greenhorn

Joined: Oct 23, 2002
Posts: 17
I have read all the above long conversation.. i feel there should be one Web Application (as it is running/designed) containing 3 sub modules named App1, App2 & App3.
For handling timeout session.setMaxInactiveInterval(<duration_in_sec> .... should be the best possible solution which can be employed.....
and <duration_in_sec> should vary according to the sub module. i.e. for App1 it should be session.setmaxInactiveInterval(20*60), for App2 (40*60) and for App3 (5*60)...


Rishi Tandon<br />SCJP 1.2<br />SCBCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session time out
 
Similar Threads
Problem with referencing session information from 2 contexts, one a subfolder of another
Communicating Among differennt Applications in Tomcat
Session problem!
How to integrate two web applications having two different context paths
JSP doesn't work in Linux server.