How can I close the sessions in jsp ?

Hello All,

    I'm new to jsp. Our present Intranet is designed in jsp with back-end as Oracle. Previously it is

designed by other employees. My present requirement is " I need to create a login page, if the username

and passwords are correct then we will go to another page which is having logo presenet employee log

status, Garde, Department information on the top header" For this they used "Session.putValue("Name",

VariableName), Session.putValue("Dept",VariableName)...". What I need here is how can i close the

sessions if I click "Log out." At present simple I redirected the page to homepage when I click log out (The

problem here is if I click back button I was able to see the previous page but it is not the correct way).

Thanks
LVL 13
PillalamarriVenkateswaraRaoAsked:
Who is Participating?
 
DarkHillConnect With a Mentor Commented:
Hi,

You could simply call the following function:

session.invalidate();
0
 
PillalamarriVenkateswaraRaoAuthor Commented:
Thanks for the responce.

session.invalidate(Name);

is it sufficient??

0
 
krishna kishore mellacheruvu venkataConnect With a Mentor Commented:
You can use session.removeAttribute(Name) also, to remove the object from the session.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
PillalamarriVenkateswaraRaoAuthor Commented:
Can u please give the steps if I click Logout Hyperlink.

Thanks
0
 
DarkHillCommented:
session.invalidate(); destroys all active sessions. If you want to destroy single sessions only, you can use code as above or simply set the session value to a null value.
0
 
DarkHillCommented:
Upon logout, forward to a .jsp page with the code to invalidate the session and the redirect back to the homepage.
0
 
krishna kishore mellacheruvu venkataConnect With a Mentor Commented:
Upon logout you can do it as

session.setAttribute("X_SESSION", null);

and forward to the intended jsp.
0
 
PillalamarriVenkateswaraRaoAuthor Commented:
I had writen the below code for my logout page.
If I click logout in my page then i'm redirect to logout.jsp.
If I click Back button then I able to see the values there. But I need to get as "Ur session has been expired"  message.
Please give me ur suggestions.

Thanks
<BODY bgcolor="#e9f2db">
<%@ page import="java.sql.*"%>
<%@ page import="java.util.StringTokenizer"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="javax.servlet.*" %>
<%@ page buffer="NONE" %> 
<%@ page autoFlush="true" %> 
<%
try 
{
	session.invalidate();
	out.println("Your session has been closed. Click");
	out.println("<a href=http://abc/bcd/cde.jsp>here");
	out.println("</a>");
} 
catch(NullPointerException npe) { 
 out.println(npe.toString()); //catch errors and print them out 
}  
catch(Exception e) { 
 out.println(e.toString()); //catch errors and print them out 
}   

Open in new window

0
 
ManishConnect With a Mentor LeadCommented:
are you creating session there?
Are you checking that session has expired in that jsp?

This link may help you.
http://www.experts-exchange.com/Programming/Languages/Java/Q_22698182.html
0
 
PillalamarriVenkateswaraRaoAuthor Commented:
Befrank up to now I was not used ur solutions.
Anyway thanks for the information. If I get any prob when I works on this issue I post a open question. Plese participate in that. THanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.