clear session history and display the page again

Posted on 2004-11-14
Last Modified: 2008-02-01
I have a jsp page (out.jsp) wich contains a form with submit button. When "submit" is clicked, out.jsp calls a java servlet ( which then performs some operations and the results are again displayed by out.jsp. I track session history with HttpSession(inside and display it each time "submit" button is pressed. In other words, I display all previous paramters the user selected. I need to create a "clear history" button. I guess I can try to use session.removeAttribute inside the servlet but I don't know how I would know which button was pressed (submit or clear?)

So, my question is in which file (out.jsp or and how  I would create a function for clearing history, so that out.jsp is displayed again but without session history displayed.
Question by:na77
    LVL 92

    Accepted Solution

    set a value for your button, and check it in your servlet
    or have the button call a different servlet
    LVL 11

    Assisted Solution

    Or you can have a hidden field name "action"

    <input type="hidden" name="action">

    and when you click submit or clear you have to set it value by javascript to "submit" or "clear"
    and then in servlet use request.getParameter("action") and check whether it is submit or clear.
    LVL 29

    Assisted Solution

    Just make the clear button a link to the controller with the parameter clear as you aren't submitting any form info.


    Then in controller, check params and then if the sction is clear, call session.invalidate() to destroy session then create a new sesion with request.getSession(true) and forward back the the out.jsp page.
    LVL 29

    Expert Comment

    I'm easy but I gave them the code required to kill the session so that's at least part of the solution...
    LVL 11

    Expert Comment

    I think I answered the question too.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Running Java Servlet inside Eclipse Luna 6 127
    Images won't display in JSP pages 30 164
    maven project jars 7 40
    java operators 3 71
    If you're not part of the solution, you're part of the problem.   Tips on how to secure IoT devices, even the dumbest ones, so they can't be used as part of a DDoS botnet.  Use PRTG Network Monitor as one of the building blocks, to detect unusual…
    Great sound, comfort and fit, excellent build quality, versatility, compatibility. These are just some of the many reasons for choosing a headset from Sennheiser.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now