File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Session problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Session problem" Watch "Session problem" New topic

Session problem

Hazel Sisson

Joined: Feb 12, 2002
Posts: 17
I am making a web application that uses sessions to tell if a user is logged in or not. If the user is not logged in they are meant to be redirected to an error page.
I am including a JSP (pSession.jsp) in the main JSP using this:
<jsp:include page="common/pSession.jsp" />
I am aiming to include pSession.jsp in many pages.
Here is pSession.jsp:
<% request.getSession(false);
if ( session != null)
//if the user name is null, go to error page:
if (session.getValue("userName") == null)
// print the user's name: %>
<%= session.getValue("userName")%>
else // the session does not exist
If there is a session present it works fine and the user name is printed out to the main page.
But if there is no session the page doesn't redirect as I intended!
Could anyone tell me why?
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
Redirect is sending a response back to the browser with the new URL. You want to use the RequestDispatcher's object forward method.

So much trouble in the world -- Bob Marley
Hazel Sisson

Joined: Feb 12, 2002
Posts: 17
OK, thanks!
I agree. Here's the link:
subject: Session problem
Similar Threads
Frameset in JSP not displaying
Session and NullPointerException! URGENT!
problem without logout, how to solve it
IllegalStateException when redirecting the response...
Session Tracking and Security Checking