• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

jsp redirections if session is null

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a file named index2.jsp given below:




The sessionManagement.jsp file is as given below:




Problem:
Prior to hitting the index2.jsp page I have created a session in a servlet and set the MaxInterval value to 15(seconds) using the inbuilt setMaxInterval... function. Thereafter I use a sendRedirect to get to index.jsp page.
The index.jsp that contains a link pointing to index2.jsp. When I click it after 15seconds my response.sendRedirect("/sessionExpired.jsp") doesn't go to sessionExpired.jsp but prints only OSR(content of index2.jsp) on the index2.jsp page.

I don't want it to go to index2.jsp page if the session becomes invalid. I want it to redirect to sessionExpired.jsp instead. How should I do this?
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check this interesting link
http://stackoverflow.com/questions/961124/cannot-redirect-with-the-response-sendredirect
 
Sheriff
Posts: 26777
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It might be something to do with the way that <jsp:include> works, I don't know. But I would never have done it that way in the first place, so I don't really care either. You should really make the decision about whether to redirect or not before you run any JSPs at all. Especially if the question is "Is the session timed out?" -- that sort of thing should be in a servlet filter.
 
Rahul Dhamecha
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, thanks for your replies.

The problem was with the jsp:include! Instead of using that I used the include directive. Apparently the former returns the result of the resultant servlet and embeds it in the index2.jsp file. However, include directive works differently.

However, as paul pointed out I am going to keep the session Management code in a servlet which results to a better design.

Thanks again.
 
reply
    Bookmark Topic Watch Topic
  • New Topic