Is it possible to invalidate session when I click my browsers back button

Hai
I have a question.
I am building a jsp page with multiple forms.As of now,
no login system has been implemented.
I need my session to time out when the client click on the back
button on the browser to prevent data corruption.
Is there a possible way to do this in Java/ Script
I know the use of session.invalidate() but how to tie it up to the
browser's back button
A second problem
If I use session.invalidate() on Tomcat 3.2
I find that it is not invalidated.But this same function on tomcat 4
doesn't have any problem
Could anyone help on these issues
Thanks

You don't mean you want to invalidate session every time you move to a new page, do you? If you do, after implementation of login system the users will be asked for passwords at each page. If you don't, it's better to use headers for your response.
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Expires", "-1");

Similar Messages

  • Invalidate session when user clicks back button

    I want to invalidate the session when user clicks back button, so that user cannot refresh and reload a page.
    Any suggestions will be highly appreciated.
    Message was edited by:
    sam_amc

    * SessionInvalidator.java
    * Created on October 27, 2006, 9:18 AM
    package web;
    import java.io.*;
    import java.net.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    * @author javious
    * @version
    public class SessionInvalidator extends HttpServlet {
        /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
         * @param request servlet request
         * @param response servlet response
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            String reposted = request.getParameter("reposted");
            if("true".equals(reposted))
                HttpSession session = request.getSession(false);
                if(session == null)
                    // This is step 4 and beyond
                    out.println("<html>");
                    out.println("<head>");
                    out.println("<title>Servlet SessionInvalidator</title>");
                    out.println("</head>");
                    out.println("<body>");
                    out.println("<h1>Servlet SessionInvalidator at " + request.getContextPath () + "</h1>");
                    out.println("I said, your session is now invalid! Now where are those Duke Dollars at?");
                    out.println("</body>");
                    out.println("</html>");
                else
                    Integer hitCount = (Integer)session.getAttribute("hitCount");
                    if(hitCount == null)
                        // This is step 2 (the "good" - "stay" page.)
                        out.println("<html>");
                        out.println("<head>");
                        out.println("<title>Servlet SessionInvalidator</title>");
                        out.println("</head>");
                        out.println("<body>");
                        out.println("<h1>Servlet SessionInvalidator at " + request.getContextPath () + "</h1>");
                        out.println("Your session is good.<br>");
                        out.println("If you click the browser's back button, you will invalidate your session.");
                        out.println("</body>");
                        out.println("</html>");
                        hitCount = 1;
                        session.setAttribute("hitCount", hitCount);
                    else
                        //We've used up our good visit
                        session.invalidate();
                        // This is step 3
                        out.println("<html>");
                        out.println("<head>");
                        out.println("<title>Servlet SessionInvalidator</title>");
                        out.println("</head>");
                        out.println("<body>");
                        out.println("<h1>Servlet SessionInvalidator at " + request.getContextPath () + "</h1>");
                        out.println("Your session is now invalid");
                        out.println("</body>");
                        out.println("</html>");
            else
                // because the javascript in the following output will never allow a user
                // to continue clicking back any further than this, we can safely create the session.
                // (or perhaps the session can already be created here and this may not be necessary).
                // A problem lies where if the user chooses to "select" a page back in history they thereby
                // potentially skip back "over" this functionality, thus defeating the purpose of it.
                request.getSession(true);
                // This is step 1 (indirection)
                out.println("<html>");
                out.println("<head>");
                out.println("<title>Servlet SessionInvalidator</title>");
                out.println("</head>");
                out.println("<body onload=\"document.getElementById('invalidatorForm').submit()\">");
                out.println("<h1>Servlet SessionInvalidator at " + request.getContextPath () + "</h1>");
                out.println("<form id=\"invalidatorForm\" action=\"SessionInvalidator\" method=\"POST\">");
                out.println("<input type=\"hidden\" name=\"reposted\" value=\"true\">");
                out.println("</form>");
                out.println("</body>");
                out.println("</html>");
            out.close();
        // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
        /** Handles the HTTP <code>GET</code> method.
         * @param request servlet request
         * @param response servlet response
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
        /** Handles the HTTP <code>POST</code> method.
         * @param request servlet request
         * @param response servlet response
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
        /** Returns a short description of the servlet.
        public String getServletInfo() {
            return "Short description";
        // </editor-fold>
    }The problem with even attempting to do this is that with today's browser capabilities, users can optionally choose to jump to a particular page in the browser history and this may not necessarily be the most recent page. In this case, you would also want to invalidate the user's session after already having been there (whatever page that may be). Then you have situations when the user may wish to jump back in history to external pages they were visiting before they reached your own site's pages. Then what happens when they start clicking forward, forward, etc... from there? This is why I prefer writing Swing Clients as alternatives to browser applications. There are soo many possible ways break web applications made for standard web browsers both maliciously and simply by accident or irregular user patterns. Regardless, this servlet would work based on the assumption that all the user(s) would "ever" do aside from moving logically forward is clicking on the browser's "back" button.
    cheers!
    Message was edited by:
    javious

  • How can i invalidate Session when a browser crashes?

    Hi
    How can i invalidate session when a browser window closed or crashed unexpectedly.
    If user closed the browser window using File->Close, then i'm calling javascript function .... and it is working fine. But when browser window is hanged and closed using ENDTASK, how can i kill that session.
    Please help
    Thanks
    -Vidyadhar

    Well you can't. Execution halts, so anything you would want to do is made impossible: that's why crashes are the #1 enemy of any software developer (that and impossible deadlines). The webserver will remove the session manually when it times out though.

  • I am trying to download my paid for Elements 13 upgrade. When I click on the "download" button, I recieve this message: 413  Header Length too Large

    I am trying to download my paid for Elements 13 upgrade. When I click on the "download" button, I receive this message: 413  Header Length too Large.  Help?

    You can download using direct download link , which I had provided.
    Download Photoshop Elements products | 13, 12, 11, 10
    During installation , when prompted enter serial number and proceed with the installation .
    If you had purchased upgrade serial number.
    First enter Photoshop Elements 13 serial number .
    Then it will ask for previous qualifying version serial number.
    From the drop down list , select Photoshop Elements 12 and then enter Photoshop Elements 12 serial number 

  • OATS - Browser is not getting launched when I click on the record button.

    Hi,
    I've just installed Oracle Application Testing Suite in my machine. During the installation process I was intimated that the EmpAppServer in the installation path does not contain the jboss binaries. However, it allowed me to continue with the installation.
    I've installed the OATS and the OpenScript. I need to record scripts for a web application. Now when I click on the record button, the browser is not being launched. I don't get any error message too. I'm not sure if this issue has got anything to do with jboss.
    Can someone please help me out?
    Thanks!

    Try to run the batch files in the OpenScript directory to disable and re-enable the browser helpers. Which browser do you have OpenScript set to launch, IE or FF? Which version of IE and FF are installed on your machine?
    \OracleATS\OpenScript
    InstallBrowserHelpers.bat and UnInstallBrowserHelpers.bat

  • Why can't I view my bookmark folders in alphabetical order when I click on the bookmark button on the browser? Is there a way to see the folders in alphabetical order all the time?

    I click on the bookmarks button on the Firefox browser and the folders that hold the bookmarks are not in any particular order. I would like the folders to be in alphabetical order when I see them...when I click on the bookmarks button at the top of the browser. When I go to organize bookmarks I can sort them so they are in alphabetical order, but they do not show up that way when you just click on the bookmark button to get to your bookmarks. Any help would be greatly appreciated! Thank you!!

    http://kb.mozillazine.org/Sorting_bookmarks_alphabetically

  • Error 500 -Internal Server Error when I click on browse catelog button on Reports and Analytics in Fusion

    Hi
    I am unable to access Reports and Analytics . It throws a Error 500 -Internal Server Error when I click on browse catelog button on Reports and Analytics in Fusion
    I have all the required roles and also BIADMINISTRATOR ACCESS still I am unable to login to Reports and Analytics. I have cleared the cache also.
    My collegue who has the same roles is able to access it.
    Regards
    Avinash

    I created the showModule.xhtml in the web.view.module\src\main\resources folder and test the application and Now I'm getting the error in both deployment ways.
    a) Local deployment: Same result
    Error 500--Internal Server Error
    com.sun.faces.context.FacesFileNotFoundException: /showModule.xhtml Not Found in ExternalContext as a Resource
    at com.sun.faces.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:232)
    at com.sun.faces.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:273)
    b) Remote server:
    Error 500--Internal Server Error
    com.sun.faces.context.FacesFileNotFoundException: /showModule.xhtml Not Found in ExternalContext as a Resource
    at com.sun.faces.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:232)
    at com.sun.faces.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:273)
    Please check the below screenshots for the mappings captured in the properties window.
    http://imageshack.us/photo/my-images/5/srwebviewmodule.png/
    http://imageshack.us/photo/my-images/811/eclipseexplorer.png/
    http://imageshack.us/photo/my-images/521/cdiandrichfacesear.png/
    http://imageshack.us/photo/my-images/90/cdiandrichfaces.png/
    Thanks,
    Vijaya

  • I am trying to download from iTunes and when I clicked on the Sync button, it indicates that it is waiting to start and then says the sync failed.  what is the problem

    Trying to download from iTunes and when I clicked on the Sync button, it indicates that it is waiting to sync.  Then it comes back saying sync failed.  What is the problem ?

    Few questions..
    are you using windows or mac?
    what version of itunes are you using?
    have you EVER been able to successfully sync with itunes?
    what iOS version are you running on your phone?
    This is a great article for syncing with itunes. Good Luck
    http://support.apple.com/kb/HT1386?viewlocale=en_US

  • In Firefox 3.6.10 I was able to go forward and backwards between pages without the page defaulting to the top of the page. Is there any way to prevent the page from automatically moving to the top when using the forwards and back buttons in Firefox Four?

    I like to be able to navigate backwards and forwards without having to scroll down and find where I was previously. In Firefox Four, when using the forwards and back buttons, the page will automatically return to the top of the page. Is there any way to change this setting in Firefox Four to prevent it from doing that?

    Thanks for the response. No Time Machine, but I probably have a backup from a few months ago on an external hard drive. :/ I guess it'd have useful history, but not if it overwrote the last 3 months or so of Awesome Bar, that might not be so great.

  • When I click on the Home button, I get a message saying "The URL is not valid and cannot be loaded????????"

    When I first turn on Firefox, I only get a blank "new tab". It does not go to the Firefox Home Page. When I click on the Home button in the top right, I get the message "The URL is not valid and cannot be loaded." How can I fix this so when I open Firefox it goes right to the Firefox Home Page (or a home page of my own choosing)??

    [[How to set the home page]] has detailed instructions.
    To get back to the default home page:
    # At the top of the Firefox window, click on the Firefox button (Tools menu in Windows XP) and then click Options.
    # Select the General panel.
    # In the Startup box, click Restore to Default.
    If this isn't "sticking", you may have malware or an extension that is preventing you from making the change.

  • When I click on firefox to open in my Mac, an error shows up: plug-in object Type error: id is undefined. When I click on the OK button, firefox opens. This never happened in FF 3. What is this?

    Also when I am in a site, such as an account, and click on a highlighted link, I get another error, {Javascript Application] can't create mcafee plug-in object: Type Error: components. classes [cid] is undefined. The only mcafee I had on my computer was the secure search and I uninstalled it, but I still get this message. When I click on the OK button with the error message, then the link opens up.

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Appearance/Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]

  • Hi bought lightroom, when i clicked on the download button nothing happens

    Hi bought lightroom, when i click on the download button nothing happens how do i get the download link?

    Without system information and other details nobody can tell you much. Simply try another browser as a start.
    Mylenium

  • Firefox frequently freezes for 30-60 seconds when I click on bookmarks, bookmark buttons, almost anything really.

    Firefox frequently freezes for 30-60 seconds when I click on bookmarks, bookmark buttons, almost anything really. It has been doing this ever since I downloaded the latest update (7.0.1). It is really frustrating. Can you please help?

    You will also notice that your shift key will be emulated. Meaning that keys you will try to press will press but they will act like you are pressing the shift key when you are doing them.
    Try this, minimize the firefox window by pressing the tab on your taskbar. After doing that maximize it again. You will magically be able to click any link on your page. When you navigate to a new page however, the entire situation will start all over. My only remedy is rebooting and hoping it doesn't happen again soon.

  • Regarding Lightroom Slideshow module: When I click on the preview button I get the following error: An internal error has occurred: ?:0: attempt at index a nil value. This occurs with any group of images I select in my catalog.

    Regarding Lightroom Slideshow module: When I click on the preview button I get the following error: An internal error has occurred: ?:0: attempt at index a nil value. This occurs with any group of images I select in my catalog.

    Jeannine,
         If you follow the advice of the previous poster Julie Kmoch and then gradualy add presets back in one at a time you might be able to find the one that is causing the issue. I may be guessing, but I believe the issue has something to do with either an incompatible Preset setting (eg a older preset in newer version of LR) or a corrupt Preset.
    Say you bought LR2 and imported a bunch of Presets from the internet, cuz 'Hey these effects are cool and I don't have to recreate the wheel', and then you upgraded to LR3 (not a clean install) and now one of the Presets that calls a certain slider setting or value that is different in LR3 doesn't work anymore. This might be why it throws the error, but again I am just speculating.
    Location of LR Preset folder in Windows Vista/ Windows 7
    C:/Users/<YourUserName>/AppData/Roaming/Adobe/Lightroom/Develop Presets
    If you do not see the folder AppData, you may need to change the settings in Windows Explorer to 'Show Hidden Files and Folders'. To do that in Windows Vista/ Windows 7, open a Windows Explorer window, Click on Organize, then Foler and Search Options. Then click on the View tab and select the option button next to Show hidden files, folders and drives.
    Hope this helps a bit,
    Glenn

  • How can i do this in Captivate 7 "The idea when user click on "Correct answer" button, drag source m

    How can i do this in Captivate 7 "The idea when user click on "Correct answer" button, drag source move to drop target automatically".

    I suppose you are talking about the D&D interaction? Could you explain more? What is your level of expertise with advanced actions and Effects?

Maybe you are looking for