Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

redirecting from jsp  RSS feed

 
Jenn Person
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey, I want to include a jsp page within a couple member's only pages that will check if the user is actually logged in. How do I redirect to another jsp page?

Here is what I have so far:
<CODE>
<%
userBean user = (userBean) session.getAttribute("user");

if (user == null)
{
// forward to login page
}
%>
</CODE>
 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jenn,

There are a couple of ways of achieving this:

%>
<jsp:forward page="login.jsp" />
<%

works very well - and is the most reliable. However, you cannot add parameters to the string contained in the page="login.jsp" call - which probably isn't a problem for a login application.

I believe the above call is a server redirect, which means the server handles the redirection and is therefore a bit faster.

The other method is:

response.sendRedirect("./login.jsp");

which tells the browser to redirect to the login page. However, it does sometimes result in an illegal state exception on Tomcat (not sure why). The good thing with this approach is that you can add query string parameters in the redirection (if required obviously).

I hope that helps.

Steve
 
Jenn Person
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's perfect, thank you so much!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!