Results 1 to 10 of 10

Thread: log out problem

  1. #1
    Rituparna is offline Member
    Join Date
    Feb 2011
    Location
    India
    Posts
    22
    Rep Power
    0

    Unhappy log out problem

    hey friends,
    i am facing a problem in logout code.
    i want that once logged out, the user should NOT go back to his/her page without relogging in.
    my code goes like this inside a .jsp file...
    Java Code:
    <%
    request.getSession().invalidate();
    request.getSession(false);
    %>
     <font face=papyrus color="#ffffff" ><h1>
     Thank You! You've Been Successfully Logged Out.</h1></font>
    <hr />
    <%
    if(session.getAttribute("eml").equals("")){
        out.println("<font face=papyrus color=#ffffff size=+1>You are Not Logged In!</font>");
    }
    %>
    but whenever i am clicking on the back button on the browser, the previous page, i.e. the user page opens up.
    where am i going wrong??

    please help me here.....

    thanks in advance....

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    Is it going to your server or simply drawing the user page from cache?

    If it is hitting your server then you have a flaw in your security in that you aren't checking whether someone is logged in.

  3. #3
    vaibhavspawar is offline Member
    Join Date
    Jun 2010
    Posts
    17
    Rep Power
    0

    Default

    Hello Rituparna,
    Try this out...
    Have a script tag for javascript & insert this statement into your javascript code.
    "history.back(-1);"

    All the best :)

  4. #4
    Rituparna is offline Member
    Join Date
    Feb 2011
    Location
    India
    Posts
    22
    Rep Power
    0

    Default

    Thanks, how will i check the session here? by this code whenever i try to back to this page it'll show error, no? but i want this to happen only the user logs out.

  5. #5
    SKN
    SKN is offline Member
    Join Date
    Mar 2011
    Posts
    1
    Rep Power
    0

    Default

    Hello
    You can use a servlet filter to manage the login session, Appart from servlet the filters will provide new request , aslo there are new Filter Api for log and seesion validation,
    Try this script

    <script language="JavaScript">
    window.history.forward(0);
    </script>

    hope ur problem will be solved
    else send me mail to me,
    My emailid sreekandannatarajan@gmail.com

  6. #6
    baloda is offline Member
    Join Date
    Nov 2010
    Location
    New Delhi
    Posts
    50
    Rep Power
    0

    Default

    i had same problem. this code had worked for me

    session=req.getSession(false);
    if(session!=null){
    session.invalidate();
    }


    http://java-sql.blogspot.com/

  7. #7
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    logout.jsp
    Java Code:
    <%
      session.removeAttribute("eml");
      session.invalidate();
    %>
    // the page where you are checking the session
    <%
    String eml=(String)session.getAttribute("eml");
    if(eml==null){
    %>
    Session ended
    <%
    {
    %>
    Swastik

  8. #8
    only_java is offline Member
    Join Date
    Mar 2011
    Posts
    16
    Rep Power
    0

    Default

    If you want to use browsers back button. then create cookies and make one java script function which can track your cookies and call that java script function on body load tag in jsp page.

  9. #9
    Rituparna is offline Member
    Join Date
    Feb 2011
    Location
    India
    Posts
    22
    Rep Power
    0

    Default NOthing's working

    No, it's not working at all. Going through only-java's suggestion i changed my login code like this--
    Java Code:
     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");
                      Cookie ck=new Cookie("user", type);
                       response.addCookie(ck);
               rd.forward(request, response);
               }
     else if(type.equals("booker")){
                   RequestDispatcher rd=request.getRequestDispatcher("Booking.jsp");
                         Cookie ck=new Cookie("user", type);
                          response.addCookie(ck);
               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);
            }
    i am checking the cookie value in the Administer page by..
    Java Code:
    function chkCookie(){
      var user=getCookie("user");
      if (user!=null && user!="")
      {
      alert("Welcome again " + user);
      }
    else
    {
    prompt("Please Login");
     
    }
    }
    and calling it on the body onload tag.
    but this time it's not showing the Admnstr page at all.

  10. #10
    Rajaa is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default

    Hi friends U try this code:

    1)login.jsp:

    <html>

    <head>

    <title>User Login</title>
    </head>
    <br>
    <body Bgcolor ="#0099cc"><hr><hr>

    <form method="POST" action="action.jsp">
    <p><b>UserName:</b> <input type="text" name="UserName" size="10"></p>
    <p><b>Password:</b> &nbsp;&nbsp;<input type="Password" name="Password" size="10"></p>
    <p><input type="submit" value="Submit" name="submit"><input type=
    "reset" value="Reset" name="reset"></p><hr><hr>
    </form>

    </body>

    </html>

    2)action.jsp:

    <%@page import="java.util.*" %>
    <script>
    function go() {
    window.location.replace("logout.jsp",'window','too lbar=1,location=1,directories=1,status=1,menubar=1 ,scrollbars=1,resizable=1');
    self.close()
    }
    </script>
    <%String str = request.getParameter("UserName");
    session.setAttribute("UserName", request.getParameter("UserName"));%>
    Welcome to <%= session.getAttribute( "UserName" ) %>
    <% if (session.getAttribute("UserName").equals("")){%>
    <a href="login.jsp"><b>Login </b></a>
    <%}
    else{%>
    <a href="javascript:go()"><b>Logout</b></a>
    <%}
    %>

    3)logout.jsp:

    <%session.invalidate();%>
    You have logged out. Please
    <a href="a.jsp"><b>Login</b></a>

    with regards Rajaa Mohaideen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •