response.sendRedirect throws bug

0

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?

    
asked by nachfren 16.03.2017 в 18:08
source

1 answer

1

I leave you a solution put the following Script

<script type="text/javascript">
         {
            if(history.forward(1))
            location.replace(history.forward(1));
         }
</script>

This prevents you from navigating backwards in the browser in the temple that you require that has no case or should not go backwards.

    
answered by 16.03.2017 / 20:13
source