• 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

include page ...problem

 
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am not able to figure out this ..

In the jsps of my application ...I check for session at the beginnig of the page..

if it is null...redirect the user to a page ..saying Invalid session...

This was working fine in my local(Tomcat) and remote (WAS 5.1)


since there was a duplicity of code,this session checking code was moved int a jsp and in each jsps of the application,we include this session jsp

But now the problem is ...even though the session is null..and it displays ...
"invalid session"..the rest of the page is also getting shown to the user..

Why is the page also getting shown???

Regards
 
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your main jsp structure is:
1. include session jsp
2. more jsp codes in the page

then, what ever session jsp returns, which sometimes is 'invalid session' html codes, will appear, and the processing of the main jsp will continue in #2, thereby #2 also ALWAYS gets displayed.

You have no code in between #1 and #2 to stop it from doing that.

The goal is that the #2 is not processed if 'invalid session' happens.

Can you try put a 'return;' statement at the end of the 'invalid session' codes? The jsp is converted into a servlet and the 'return;' will terminate the method processing the page.
 
Jesus Angeles
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's what I mean. One solution below:

main jsp

0. boolean valid=true;
1. include session jsp
1.a. if (not valid) {return;}
2. more jsp codes in the page


inside #1, set valid to false if invalid session

This above is just to explain to you what I mean. You may or may not resolve it as above, and use other resolutions, because using above, there will now be a dependency between the main jsp and session jsp; but definitely, above will solve your problem.
[ February 03, 2008: Message edited by: Jesus Angeles ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As you're finding out, checking for the nullness of the session object itself is unreliable and frustrating.

A much easier and more solid way to do this is to bind an object to session when the user logs in. Then, with each hit, test that for null instead of the session itself.

By default JSPs automatically generate a session object.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But in my session jsp ..i have code...that checks for user session is null or not and if it is null do a sendRedirect to a different page..

Why is the sendRedirect not executing???
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by A Kumar:
Why is the sendRedirect not executing???


Because as Ben said, the session will never be null. If the session expires, a new one will be automatically generated. To test whether the session has expired, it's best to bind an object to the session -- if that object is no longer there, that's when you do the redirect.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My code in the session checling page is as follows

<%

String user=(String)session.getAttribute("loggedUser");
if(user==null) {
System.out.printn("Invalid");
response.sendRedirect("InvalidSession.jsp");
}

%>

why is the sendRedirect not working even though invalid is getting printed???
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
response.sendRedirect does not stop the execution of your JSP.

You need to either branch your code in such a way that the call to sendRedirect is the last statement on the page or, call return;
immediately after calling sendRedirect.


[ February 05, 2008: Message edited by: Ben Souther ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic