Results 1 to 4 of 4
Thread: problem in session invalidation.
- 11-16-2010, 09:09 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 9
- Rep Power
- 0
problem in session invalidation.
i have written code to logout the user session in my project.
but its not if i click back option, the session is still alive. please suggest me.
my code is Java code:
public void logout()
{
session = request.getSession();
session.invalidate();
RequestDispatcher rd = new RequestDispatcher("Homepage");
rd.forward(request,response);
}
After logout, if I click back , the session is still alive.
- 11-16-2010, 09:51 AM #2
Try this below code.
HttpSession session = req.getSession(false);
if(session != null){
session.invalidate();
}Ramya:cool:
- 11-26-2010, 09:17 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 1
- Rep Power
- 0
Hi Jagdeesh,
For this u need to check session object (which u created) is null or not if it is null then u need to redirect to login page.
I am giving some example:
this is in server side code ..
HttpSession session=request.getSession(false);
//here u are geeting the user name from session
String strname=(String) session.getAttribute("username");
//here u are checking the session object (the value which u store in session) if it is null u are redirecting..
if(username==null){
//session=request.getSession();
RequestDispatcher rd=request.getRequestDispatcher("/Login.jsp");
rd.forward(request, response);
return;
}
HttpSession session=request.getSession(false); //here u are geeting the user name from session String strname=(String) session.getAttribute("username"); //here u are checking the session object (the value which u store in session) if it is null u are redirecting..
if(username==null){ //
session=request.getSession();
RequestDispatcher rd=request.getRequestDispatcher("/Login.jsp");
rd.forward(request, response); return; }
Like this only u need to check in jsp also.
It can surely redirect to login page..
While u logout use must invalidate the session .
write this code in logout servlet
HttpSession session = request.getSession(false);
if(session!=null)
{
session.invalidate();
}
RequestDispatcher rd=request.getRequestDispatcher("/Login.jsp");
rd.forward(request, response);
return;
HttpSession session = request.getSession(false);
if(session!=null) { session.invalidate(); }
RequestDispatcher rd=request.getRequestDispatcher("/Login.jsp");
rd.forward(request, response); return;
It is better to use filter to check the session object otherwise u need to check the condition in every servlet it become redundancy ..
I hope this is useful for u...
- 12-06-2010, 04:05 PM #4
Member
- Join Date
- Sep 2009
- Location
- Bangalore, India
- Posts
- 10
- Rep Power
- 0
Hi Jagdeesh,
Try this
Also make sure that in each of the JSP page, you are checking whether the session is new. If its new then redirect to the welcome page.Java Code:HttpSession session = request.getSession(false); if(session!=null) { session.invalidate(); response.sendRedirect("/Login.jsp"); }Last edited by anubhavranjan; 12-06-2010 at 04:07 PM.
Similar Threads
-
How to Kill session at application context level by using session Id
By Kishore.Kumar in forum Java ServletReplies: 1Last Post: 04-21-2009, 11:20 PM -
Problem with Session Scope while using with Java Bean
By sulthanmytheen in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-27-2009, 10:50 AM -
How do I create session for a user when S/he login and expire the session.
By dpk_vash in forum Web FrameworksReplies: 2Last Post: 12-23-2008, 06:35 PM -
Session Problem
By irfan.ahmad in forum Java ServletReplies: 4Last Post: 10-08-2008, 10:50 AM -
how to use session variable in my problem
By Arif Baig in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 03-27-2008, 07:23 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks