• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

code for logout from jsp page

 
sunita shaw
Ranch Hand
Posts: 45
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cannot just use "session.removeAttribute()"?
 
Praful Thakare
Ranch Hand
Posts: 642
  • 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
  • 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
  • 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: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 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
  • 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: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic