Hi,
i have developed an web application using JSF.
In that, if the user remains idle in the application for more than 15min then their session should expire.
i have tried it by giving <session-timeout> tag value as 15 min in web.xml.
but i don't know how to redirect the user to the login page after session timeout.
Is it possible to use session.setMaxInactiveInterval() in my application to expire the session after that particular time?
please give me some ideas to solve this issue.

Regards,
Indu

Recommended Answers

If you are using Seam than the solution given at the link below will be helpful to you. What it does is that it periodically checks for new session through javascript timer and Seam component annotated with @WebRemote. The javascript timer is reset at every normal and AJAX request.

Jump to Post
HttpSession session = request.getSession();
if(session==null){
	RequestDispatcher rd = context.getRequestDispatcher("/demo/inner.jsp");
	rd.forward(request,response);
}

Cooked from different google links and untested. Try it and see.
I'm not JSP maverick either

Jump to Post

All 6 Replies

If you are using Seam than the solution given at the link below will be helpful to you. What it does is that it periodically checks for new session through javascript timer and Seam component annotated with @WebRemote. The javascript timer is reset at every normal and AJAX request.
http://in.relation.to/3266.lace

You can also have a look at the one described in
http://techieexchange.wordpress.com/2008/02/21/jsf-session-expired-timeout-solution/

i'm not using seam.
I'm using JSF along with Richfaces.
can u suggest me some other ideas on how to solve it?

HttpSession session = request.getSession();
if(session==null){
	RequestDispatcher rd = context.getRequestDispatcher("/demo/inner.jsp");
	rd.forward(request,response);
}

Cooked from different google links and untested. Try it and see.
I'm not JSP maverick either

Hi,
I have used like this before.
But now what i have to do is to calculate the session time of each user. I can do this if the user presses the logout button by calling a function. I don't know to call the same function when the session expires automatically.

Suppose,if the user login into the application and performs some operations then if the user remains idle for the maximum session time out i have to calculate the session time and then redirect them back to login page.
hence i have to call the function to calculate the session time before redirecting to login page after session time out.
hope u can identify my issue.
waiting for reply to solve this.


Regards,
Indu

When the use logs in, put its username in the session:

session.setAttribute("USER", username);

At the beginning of each page you can do this:

String username = (String)session.getAttribute("USER");
if(username==null) { // session expired
// FORWARD WITH ANY WAY YOU WANT

// I don't know about this one. I usually use the forward tag
RequestDispatcher rd = context.getRequestDispatcher("/demo/inner.jsp");
rd.forward(request,response);
}

evstevemd

I think i didnt clearly explain my problem in my previous post.
Actually,I have to enter the session time of each user in the database. To do this i have a function in the bean. I can call this function when the user click the logout button and then redirect the user to login page from that function. But i cannot call this function when the session expires automatically after the session time out. I'm using jsf with richfaces.
Thanks in advance.

Regards,
Indu

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.