• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

redirecting from jsp

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's perfect, thank you so much!!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic