• 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

JSP HttpSession issue - some pages work, some don't

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.

I have a strange issue. The first page (mainIndex.jsp) uses a login page called index.jsp to test whether a user is authenticated and if not, shows a login form. If user is authenticated, it uses jsp:forward to forward to mainIndex.jsp. A Java servlet is used by index.jsp to check the user's details are correct and if so, stores the authentication information in the HttpSession (sets "authenticated" value to true and "username" to the username of the user). This works fine and the username is shown on mainIndex.jsp.

The second page is just a test page hyperlinked from mainIndex.jsp that is supposed to get the HttpSession associated with the request header and show the username stored in the HttpSession. This does not work. Does anyone know why?

By the way, I am using Apache Tomcat 5.5.9 under Windows XP Professional but not using J2EE security as I don't have access to the server configuration files, in order to set it up.

Thanks.
Jon


=== mainIndex2.jsp ===



=== test.jsp ===
 
Sheriff
Posts: 67748
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


This is completely unnecessary. The session implicit variable is already set up when a JSP page is invoked.
 
Jon Brasted
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If that's the case, I don't understand why the HttpSession object is not passed from mainIndex.jsp to test.jsp??
 
Bear Bibeault
Sheriff
Posts: 67748
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
Yes, but the first step is to get rid of any unnecessary stuff that might be tripping you up.

Also, are you just looking for help on this spot problem, or would you like some discussion on better ways to approach the whole pattern of what you are doing?
 
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

You're logging yourself out as soon as you've tested for a valid login.
[ July 21, 2005: Message edited by: Ben Souther ]
 
Bear Bibeault
Sheriff
Posts: 67748
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
Yup, that's it. Good spot, Ben.

Jon, if you thought that that line would defer calling the invalidate method until the hyper-link was clicked, you have a basic misunderstanding of the life-cycle of a JSP.

All the Java scriptlets in a JSP are executed on the server side in order to create a plain old HTML page to send to the browser. As such, your invalidate method is being called before the page is even sent to the browser.

Do a View Source on the page and see what your anchor tag got turned into.
[ July 21, 2005: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Sheriff
Posts: 67748
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
Or, better yet, find the java file that got created on behalf of your JSP and see what code executes when the page is hit. (Under Tomcat, these can be found in the folder hierarchy rooted at $CATALINA_HOME/work).
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic