Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Log Out Problem

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    11
    My Mood
    Relaxed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Log Out Problem

    Hi,
    I 've created a website on Online Hotel Management System, everything is working fine till now in the project but one.
    I have this logIn.java file...
    package fiveStar;
     
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.*;
    import javax.servlet.http.*;
     
    /**
     *
     * @author RITU
     */
    public class logIn extends HttpServlet {
     
        /** 
         * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
         */
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
    		String type=request.getParameter("logAs");
            String id=request.getParameter("logId");
            String p=request.getParameter("pwd");
     
             try {
                Context c = new InitialContext();
              loginLocal l = (loginLocal) c.lookup("java:global/OnlineHotelManagement/OnlineHotelManagement-ejb/login!pack.loginLocal");
              if(l.logMe(id, p)){
               if(type.equals("Administrator")){
               RequestDispatcher rd=request.getRequestDispatcher("Admnstr.jsp");
              request.getSession(true);
               session.setAttribute("user", type);
               session.setAttribute("url","Admnstr.jsp" );
               rd.forward(request, response);
               }
     else if(type.equals("booker")){
                   RequestDispatcher rd=request.getRequestDispatcher("Booking.jsp");
               request.getSession(true);
               session.setAttribute("user", type);
               session.setAttribute("url","Booking.jsp" );
               rd.forward(request, response);
     }
               else{
                   RequestDispatcher rd=request.getRequestDispatcher("Error.html");
                    rd.forward(request, response);
     }
               }
     
            } catch (NamingException ne) {
                Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
                throw new RuntimeException(ne);
            }
     
    	}
    }
    and this logOut.java file..
    package fiveStar;
     
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.*;
    import javax.servlet.http.*;
     
    /**
     *
     * @author RITU
     */
    public class logOut extends HttpServlet {
     
        /** 
         * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
         */
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            try {
             HttpSession session= request.getSession(false);
             if(session!=null){
              session.removeAttribute("user");
              session.removeAttribute("eml");
              session.removeAttribute("url");
              session.invalidate();
                }
             response.sendRedirect("index.jsp");
            } finally { 
                out.close();
            }
        } 
    }

    both the files are working, that means i can log in, enter the user page, and after logging out i get redirected to index.jsp. upto this everything is working.
    But, then when i am clicking on the Back button on the browser, i get back to the previous page, from where i'd been logged out.
    how can i stop the browser to get back to the previous page?
    I mean, once logged out, the user should by no means go back to her page without re-logging, not even by clicking on the back button of the browser.
    Isn't that possible?
    If no, then why is it not possible? if it's possible, how can i make this happen for my code?

    thanks in advance..


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Log Out Problem

    Hello there,

    Another question is, can you go to the page that requires you to be logged in, even before you have logged in?

    If so then I think you might want to have a look at creating a filter and then have this filter check if the user is logged in or not when accessing certain pages and if they're not logged in, they need to be redirected to the login page or any other page of your choice.

    // Json

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,337
    Thanks
    182
    Thanked 830 Times in 773 Posts
    Blog Entries
    5

    Default Re: Log Out Problem

    To add to Json's suggestion, it sounds like the browser might be caching the previous pages, so when you hit the back button the server might not even receive a request - the client just reloads the cached page. To try and overcome this, set the headers for your pages to tell the browser not to cache the pages. You can find a lot online on how to accomplish this so I won't rehash the instructions, just be aware that some browsers might not respect the no-cache header.

  4. #4
    Junior Member
    Join Date
    Feb 2011
    Posts
    11
    My Mood
    Relaxed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Log Out Problem

    Thanks, i am trying... let's see if it's works..
    or may be i have to check the session variables everytime i enter that page......
    may b that'll help.

  5. #5
    Junior Member
    Join Date
    Feb 2011
    Posts
    11
    My Mood
    Relaxed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Log Out Problem

    Nope, it's not at all working.... dont know why? totally confused........