? with invalid session

2005-02-16 Thread Eric Lemle
If the session expires and then they click on something it runs the
action and then the action tries to get some info from the session
which causes a null pointer exception.  Is there anyway to have a
pre-filter rather than a post-filter to send them to the page that
says,
says ex.- 'your session has expired, please login again'

-Eric

Eric D. Lemle
Senior Programmer / Analyst
Intermountain Health Care
36 South State Street, Suite 1100
Salt Lake City, Utah 84111 
United States of America (USA)
(801) 442-3688 -- e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ? with invalid session

2005-02-16 Thread Rick Reumann
Eric Lemle wrote the following on 2/16/2005 4:22 PM:
If the session expires and then they click on something it runs the
action and then the action tries to get some info from the session
which causes a null pointer exception.  Is there anyway to have a
pre-filter rather than a post-filter to send them to the page that
says,
says ex.- 'your session has expired, please login again'
Sure just set up a servlet filter that looks for a valid session and if 
there isn't one you forward them to that page. Define your filter in 
your web.xml. I think the tomcat docs show an example... but for my app 
I have something like...

filter
filter-nameNdaFilter/filter-name
filter-classcom.nielsenmedia.nda.ui.filter.NdaFilter/filter-class
  /filter
  filter-mapping
filter-nameNdaFilter/filter-name
url-pattern*.do/url-pattern
  /filter-mapping
  filter-mapping
filter-nameNdaFilter/filter-name
url-pattern*.jsp/url-pattern
  /filter-mapping
In your custom Filter class which extends javax.servlet.Filter, you'll 
have a doFilter method in it where you'd add something like...

HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse)res;
String contextPath = request.getContextPath();
HttpSession session = request.getSession(false);
if (session == null) {
   log.debug(The session no longer exists);
   response.sendRedirect(contextPath+/sessionTimeOut.jsp);
   return;
} else {
 filterChain.doFilter(req, res);
}
(Could be much better ways to accomplish the above, but the above should 
work)

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]