• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jon Brasted
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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 ===
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic