Hi Vineesh,
I use a Filter to accomplish this (below).
NOTE: I'm using Tomcat 5.0.28, and this is not verified for Tomcat 5.5.9.
NOTE: User Principal object is not serialized with all other serializable
session data (anyone know why not? I would love to have a fix for this).
So, if you use a custom Realm/Principal object that stores pertinent data,
this solution may not be optimal for you.
NOTE: (from below) cookie.setMaxAge(<insert max desired age of session in
millis here>);
----- BEGIN FILTER CODE SAMPLE -----
import org.apache.log4j.Logger;
import javax.servlet.Filter;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.FilterConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import com.ditd.util.Util;
import com.gbs.security.IUserInfo;
/**
* @author John C. Dale ([EMAIL PROTECTED])
*/
public class ExtendSession implements Filter
{
private static Logger log = Logger.getLogger(
ExtendSession.class.getName());
public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException
{
try
{
try
{
HttpServletRequest request =
(HttpServletRequest)servletRequest;
HttpServletResponse response = (HttpServletResponse)
servletResponse;
IUserInfo user = (IUserInfo)request.getUserPrincipal();
if(user != null)
{
Cookie[] myCookies = request.getCookies();
Cookie cookie;
if(myCookies != null)
{
for(int i = 0; i < myCookies.length; i++)
{
cookie = myCookies[i];
if(cookie.getName() != null &&
cookie.getName().equals("JSESSIONID"))
{
cookie.setMaxAge(432000);
cookie.setPath(request.getContextPath());
response.addCookie(cookie);
break;
}
}
}
}
}
catch (Exception e)
{
log.error("Unable to pull features from database.");
log.error(Util.getStackTraceAsString(e));
}
}
finally
{
filterChain.doFilter(servletRequest, servletResponse);
}
}
public void init(FilterConfig filterConfig) throws ServletException
{
// no op
}
public void destroy()
{
// no op
}
}
----- END FILTER CODE SAMPLE -----
Bear Down,
JCD
-----Original Message-----
From: vineesh kumar [mailto:[EMAIL PROTECTED]
Sent: Monday, February 27, 2006 10:31 PM
To: Tomcat Users List
Subject: Session Timeout
Dear all,
I am having an application, which is using tomcat 5.5.9 on RedHat
enterprise linux 4.0 and java 1.4 .My problem is thet in my application,at
certain stage I am opening a window(using javascript) and loading an
applet,which simply connects to the server and get some information,at the
backend and display a graph accordingly.My problem is that,after sometime,as
i opened the window,the session is expiring.My timeout setting is tomcat
default(30 seconds).But this is not the desirable thing.Untill the user
logging out, the session should not expire. How can i achieve this. Thanks
in advance regards
vineesh
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]