Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LogOut.jsp

Status
Not open for further replies.

dvknn

IS-IT--Management
Mar 11, 2003
94
US
I have a web application developed in JSP, TomCat 4.1.18.

In the application, I am logging a user and setting the userId in the session. After the user does whatever he needs to do, he would click on LogOut.

In the LogOut.jsp, I have the following code.

<%@ page language= &quot;java&quot; %>
<%@ page import=&quot;javax.servlet.http.HttpSession&quot; %>

<%
if(request.getParameter(&quot;logout&quot;)!=null){
out.println(&quot;called Me&quot;);
session.removeValue(&quot;loginid&quot;);
session.removeValue(&quot;isadmin&quot;);
session.invalidate();
}
response.sendRedirect(&quot;login.jsp&quot;);
%>

My problem is that 'login.jsp' is never being called. Instead, it's staying on the screen from where I clicked 'LogOut'.


Can any body help me??
 
Well, I don't honestly know what your problem is and I'm not sure how much help I can be as I'm still learning myself but I'll give it a shot.

A couple of things occur to me:

a) It looks like this logout function of yours should be more a job of a servlet rather than a jsp since you are not actually displaying any information but that's mainly stylistic so it should matter very much.

b) I'm pretty sure you don't need to import HttpSession as it is imported by default anyway, just like HttpServletRequest and HttpServletResponse. Again not really important but useful to know.

c) One thing you could do to test this jsp of yours would be to remove the response.sendRedirect() call and put in some text there (&quot;hello world&quot; and &quot;foo&quot; are popular choices). If you don't see this text it means that your page isn't getting called. This in turn probably means you probably have something wrong with your link or button on the calling page.

Despite the fact that this information probably comes several months too late I hope it might help someone else out there browsing the forums.

Nescio
 
My guess is that with response.sendRedirect() you need to provide the full URL of the destination page instead of just relative path. like so:
<%
response.sendRedirect(request.getContextPath() + &quot; /destination.jsp&quot;);
%>

Hope that helps...Libaax
 
try commenting this line and then check run it:
//out.println(&quot;called Me&quot;);


Known is handfull, Unknown is worldfull
 
There might be an Exception in your code..
put your code in try statement as below:
<%
try
{

if(request.getParameter(&quot;logout&quot;)!=null){
out.println(&quot;called Me&quot;);
session.removeValue(&quot;loginid&quot;);
session.removeValue(&quot;isadmin&quot;);
session.invalidate();
}
response.sendRedirect(&quot;login.jsp&quot;);
}
catch (Exception ex) {
%>
<%=ex.toString()%>
<%
}
%>


}

Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top