jsp - How to make the page load an error page after the tomcat session timeout? -
i need provide user error page after tomcat session time out. handle created filter , added logic detect , after saying go error page.
public void dofilter(servletrequest arg0, servletresponse arg1, filterchain chain) throws ioexception, servletexception { m_log.debug("startfilter"); httpservletrequest request=(httpservletrequest)arg0; httpservletresponse response=(httpservletresponse)arg1; string title = request.getparameter("context_title"); tcsessiondata tcsession = (tcsessiondata) request.getsession.getattribute("tcsessiondata"); if((title!=null && tcsession==null) || (title==null && tcsession!=null) ){ chain.dofilter(request, response); }else if(title==null && tcsession==null) { //response.sendredirect("/error/error.jsp"); request.getrequestdispatcher("/error/error.jsp").forward(request, response); } }
after session times out see going right "if" logic , not forwarding/redirecting error.jsp. giving 404 error. tried both redirect , forward of page no success.i tired both absolute , relative path error.jsp page still see 404 error saying can't find error.jsp page. tried put error.jsp various location under webapps
directory still no luck
my application has 1 page called root.jsp. when session time out application root.jsp , after timeout wrote go error.jsp.
here web.xml
<filter> <filter-name>checksessionexpirationfilter</filter-name> <filter-class>lti.google.checksessionexpirationfilter</filter-class> </filter> <filter-mapping> <filter-name>checksessionexpirationfilter</filter-name> <servlet-name>googledrivelti</servlet-name> </filter-mapping> <servlet> <servlet-name>googledrivelti</servlet-name> <servlet-class>lti.google.googleltiservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>googledrivelti</servlet-name> <url-pattern>/service/*</url-pattern> </servlet-mapping> <session-config> <session-timeout>1</session-timeout> <!-- in minutes --> </session-config>
here folder structure
localhost:8080/error/error.jsp
here can see context name not present in url.
try (removing '/')
getservletcontext().getrequestdispatcher("/error/error.jsp").forward(request, response);
or
getservletcontext().getrequestdispatcher("error/error.jsp").forward(request, response);
Comments
Post a Comment