Solved

How can I close the sessions in jsp ?

Posted on 2008-06-16
10
800 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
ID: 21800473
Hi,

You could simply call the following function:

session.invalidate();
0
 
LVL 13

Author Comment

by:PillalamarriVenkateswaraRao
ID: 21800482
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
ID: 21800539
You can use session.removeAttribute(Name) also, to remove the object from the session.
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 13

Author Comment

by:PillalamarriVenkateswaraRao
ID: 21800553
Can u please give the steps if I click Logout Hyperlink.

Thanks
0
 
LVL 7

Expert Comment

by:DarkHill
ID: 21800559
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
 
LVL 7

Expert Comment

by:DarkHill
ID: 21800564
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
ID: 21800598
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
ID: 21800919
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
ID: 21801677
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
ID: 31467871
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 82
javap bin 2 41
jsp login check 12 43
printf performancy 11 71
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

830 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