• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

code for logout from jsp page

 
sunita shaw
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cannot just use "session.removeAttribute()"?
 
Praful Thakare
Ranch Hand
Posts: 642
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
sunita shaw
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this thread is very old...
But for the archives:

I wrote it like that:
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even in 2003, the use of scriptlets in JSP pages was discredited. Doing so in 2009 is just .

And, please read this.
 
Parth Chavda
Greenhorn
Posts: 5
Java MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic