Hey, all Java & JSP gurus,
i'm developing a website using JSP and MS SQL.
Can you please tell me the code to invalidate a session object i.e. the code for logout (to be written in JSP)

Following is my code for creating session object, on login:

HttpSession ses=request.getSession(true);
ses.setAttribute("Name",name);

i'm using the same session object to validate user status on all pages using -

Object obj=(session.getAttribute("Name"));
      String sesVar=obj.toString();
      if (sesVar != null)
      {
         //display page
       }
       else
      {
        <jsp:forward page="Error.jsp" />
      }

Please Tell me the logout code.
Any suggestions are most welcome.
Thank you.

Edited 6 Years Ago by peter_budo: Adding code tags

Hey, thanks.
This was of great help.
Will inform when the problem is solved.
Thanks.

hi friends,
i am new jsp, in my login and logout page is must. i successfully done the login page and go to the open proper window. but if i click the hyperlink it cant be logout. please the send the code

i'm trying to build a web page which permits the user to login before accessing the contents of the site. the login works fine (i did it using jsp), but i am not able to logout properly, that is, when i click on a "logout" hyperlink, it sends me to the proper page, but when i do "back" on my explorer, it gives me the previous page again. so my logout is pointless.

can anyone tell me how to prevent this from happening please?i don't know if i should use jsp, javascript or html to do this.
i need this urgently for my project.

Edited 6 Years Ago by peter_budo: n/a

Hey, all Java & JSP gurus,
i'm developing a website using JSP and MS SQL.
Can you please tell me the code to invalidate a session object i.e. the code for logout (to be written in JSP)

Following is my code for creating session object, on login:

HttpSession ses=request.getSession(true);
ses.setAttribute("Name",name);

i'm using the same session object to validate user status on all pages using -

Object obj=(session.getAttribute("Name"));
      String sesVar=obj.toString();
      if (sesVar != null)
      {
         //display page
       }
       else
      {
        <jsp:forward page="Error.jsp" />
      }

Please Tell me the logout code.
Any suggestions are most welcome.
Thank you.

You just need:

name=null;

and garbage collector will do the rest.

You just need:

name=null;

and garbage collector will do the rest.

Can you be more specific on that? What do you mean? Can you post some more code?
What is it supposed to be set to null?

This question has already been answered. Start a new discussion instead.