Search code examples
jakarta-eeservletsweb-applicationsbrowserback-button

How to use Web Browser's BACK-BUTTON ? in java web applications


in javascript we can call history.back( ); method to go back to previous page. is there any way to implement same functionality in java web applications / servlets?


Solution

  • Procedure:

    • You can use a session object conatining a Stack where each item of the Stack contains URI of a visited page.
    • On each request in your Servlet you have to push the request URI to the stack.
    • When you want do do "Back", you just pop the Stack and you redirect to the URI you got from the top of the Stack.