I have a simple web page with jsp, when I close session use:
request.getSession().invalidate();
response.sendRedirect(request.getContextPath() + "/index.jsp");
To delete the session and redirect to the main page.
But if the user clicks back to the browser you can see the page again (I understand that the page is cached) because if we refresh the page instead of appearing the username appears "null".
To avoid this, I put an if on the pages to check that it has a session and redirect to the error page:
if(session.getAttribute("nombre_usuario") == null) {
response.sendRedirect("error.jsp?txtErr=Debe registrarse en la aplicación.&urlErr=index.jsp");
}
But the response.sendRedirect
line generates an exception:
java.lang.IllegalStateException at org.apache.catalina.connector.ResponseFacade.sendRedirect (ResponseFacade.java:518) at org.apache.jsp.usuarios_jsp._jspService (usuarios_jsp.java:96)
Do you know what it can be?