Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in session

 
Maneessh saxena
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Great Ranchers,

I have a doubt in session. I mentioned session-timeout in web.xml for 1 minute. and have an error page for Exception. but I don't get this error page instead I get the same page when I refresh it after 1 min.Why this is happening.

Thanks
 
Maneessh saxena
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
web.xml to refer is given ...

<listener>
<listener-class>com.model.TestSession</listener-class>
</listener>

<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/ErrorPage.jsp</location>
</error-page>

<session-config>
<session-timeout>1</session-timeout>
</session-config>
 
Maneessh saxena
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package com.model;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class TestSession implements HttpSessionListener {

public void sessionCreated(HttpSessionEvent arg0) {
// TODO Auto-generated method stub
System.out.println("Session created ...");

}

public void sessionDestroyed(HttpSessionEvent arg0) {
// TODO Auto-generated method stub
System.out.println("Session destroyed...");
throw new RuntimeException();

}

}
 
Santosh Raveendran
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
raunak

How you are checking for a invalid session , specify the jsp code

or the place where you redirecting or dipatching to error page.

Cheers
Santhosh
 
Praveen Kumar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , You can try this.


Write a class and implements HttpSessonListerner and in SessionDestroyed() throw an exception or sendError(somecode).

Write an <error-page> element , catch that exception there.

Here you can write your own customised JSP as you want.
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<error-page> DD element is invoked by web-container in case of any error [Http Status error] or exception only when the container is serving a client's response.

a) Client asks for resource X
b) If there is an exception/error in the process of Container serving that resource then the container will redirect to the error page defined by <error-page> DD element.
In your case its a listener and not a client request and hence the excpetion is simply logged into the container log files.





Write a class and implements HttpSessonListerner and in SessionDestroyed() throw an exception or sendError(somecode).

Futher in your listner you cannot get ServletResponse object which makes sense. HttpSessionEvent does not have any method to get ServletResponse object and hence there is no question of invoking sendError()

Hope its clear
 
Maneessh saxena
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Deepak Jain:
<error-page> DD element is invoked by web-container in case of any error [Http Status error] or exception only when the container is serving a client's response.

a) Client asks for resource X
b) If there is an exception/error in the process of Container serving that resource then the container will redirect to the error page defined by <error-page> DD element.
In your case its a listener and not a client request and hence the excpetion is simply logged into the container log files.





Futher in your listner you cannot get ServletResponse object which makes sense. HttpSessionEvent does not have any method to get ServletResponse object and hence there is no question of invoking sendError()

Hope its clear


Hi Mr. Jain,
Thanks for your kind reply. Actually my requirement is to dipatch the request to Login jsp say, when session is timed out. I thew an Exception i sesionDestroyed and set <error-page> in D.D. but instead of going to error page set, it remains on the same page with a message on console, "Session Created .... " when I refreshed aftee session timed out. To meet my requirement how could I go about.

Thanks & Regards
 
Rajit Patel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raunak,

You can use filter to fulfill your requirement. In filter, get the session from request using

HttpSession session = httpServletRequest.getSession(false);

it gives a older session, check session is valid or not, if not then you can redirect your request to Login page.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic