Solved

How can I close the sessions in jsp ?

Posted on 2008-06-16
10
797 Views
Last Modified: 2012-05-05
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
0
Comment
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 7

Accepted Solution

by:
DarkHill earned 100 total points
Comment Utility
Hi,

You could simply call the following function:

session.invalidate();
0
 
LVL 13

Author Comment

by:PillalamarriVenkateswaraRao
Comment Utility
Thanks for the responce.

session.invalidate(Name);

is it sufficient??

0
 
LVL 10

Assisted Solution

by:krishna kishore mellacheruvu venkata
krishna kishore mellacheruvu venkata earned 75 total points
Comment Utility
You can use session.removeAttribute(Name) also, to remove the object from the session.
0
 
LVL 13

Author Comment

by:PillalamarriVenkateswaraRao
Comment Utility
Can u please give the steps if I click Logout Hyperlink.

Thanks
0
 
LVL 7

Expert Comment

by:DarkHill
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 7

Expert Comment

by:DarkHill
Comment Utility
Upon logout, forward to a .jsp page with the code to invalidate the session and the redirect back to the homepage.
0
 
LVL 10

Assisted Solution

by:krishna kishore mellacheruvu venkata
krishna kishore mellacheruvu venkata earned 75 total points
Comment Utility
Upon logout you can do it as

session.setAttribute("X_SESSION", null);

and forward to the intended jsp.
0
 
LVL 13

Author Comment

by:PillalamarriVenkateswaraRao
Comment Utility
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
 
LVL 11

Assisted Solution

by:Manish
Manish earned 75 total points
Comment Utility
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
 
LVL 13

Author Closing Comment

by:PillalamarriVenkateswaraRao
Comment Utility
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now