• 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

Session problem

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
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)
{
response.sendRedirect("/noSess.jsp");
}
else
{
// print the user's name: %>
<%= session.getValue("userName")%>
<%}
}
else // the session does not exist
{
response.sendRedirect("/noSess.jsp");
}
%>
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?
Thank-you,
Hazel
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Redirect is sending a response back to the browser with the new URL. You want to use the RequestDispatcher's object forward method.
 
Hazel Sisson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, thanks!
Hazel
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic