wood burning stoves 2.0*
The moose likes JSP and the fly likes code for logout from jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "code for logout from jsp page" Watch "code for logout from jsp page" New topic
Author

code for logout from jsp page

sunita shaw
Ranch Hand

Joined: Apr 06, 2003
Posts: 45
i'm in an urgent need for a complete code for logout from a jsp page.i've tried a number of ways but things didnt work out. just see if anyone can help me out as soon as possible.
-Thanks
amanda wu
Greenhorn

Joined: Mar 16, 2003
Posts: 25
cannot just use "session.removeAttribute()"?
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 614
Hi sunita
Try this out
At starting of ur jsp page include a file say checksession.jps which will look somewhat like this
CHECKSESSION.jsp
<%@ page language="java" import="java.sql.*"%>
<%
if(session.getAttribute("SomeAttribute")== null)
{
give ur message and redirect
to some page say login page
ex:- out.println("<script>parent.location.href='Login.jsp'</script>");

}
%>
and on logout write this code

<%

session.invalidate();
out.println("<script>parent.location.href='Login.jsp'</script>");
%>

Hope this solves ur problem
cheers
[ April 10, 2003: Message edited by: Praful Thakare ]

All desirable things in life are either illegal, banned, expensive or married to someone else !!!
sunita shaw
Ranch Hand

Joined: Apr 06, 2003
Posts: 45
Thanx hth and Praful for the immediate help that you provided me .Praful your code was of greate help . it really worked perfectly well.
thanx once again
Benoît de Chateauvieux
Ranch Hand

Joined: Aug 10, 2007
Posts: 183
I know this thread is very old...
But for the archives:

I wrote it like that:


SCJP5 | SCBCD5 | SCEA5 Part 1
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Even in 2003, the use of scriptlets in JSP pages was discredited. Doing so in 2009 is just .

And, please read this.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Parth Chavda
Greenhorn

Joined: Apr 21, 2013
Posts: 5

Hey Friend use this code in jsp page

<%
if(request.getParameter("logout")!= null)
{
session.removeAttribute("uid");
session.invalidate();
response.sendRedirect("index.html");

}
%>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Parth Chavda wrote:Hey Friend use this code in jsp page

Again, as already pointed out. Java scriptlets should no longer be used in JSP pages.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: code for logout from jsp page
 
Similar Threads
JSP login/logout session problem
link html to controller
javascript called within JSP
Log Out Problem
unable to exceute logout program