Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session tracking with model 1

 
Roger Graff
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've developed several model 2/struts based applications, but not a model 1 based app.
When using a model 1 architecture, is the session id sent back to the client implicitly (via a cookie), or do I have to handle that programmatically?
Thanks,
Graff
 
Roger Graff
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the answer I was looking for in the book "Core Servlets & JSP" by Marty Hall. It states that by using the HttpSession class, session management/cookies are taken care of behind the scenes. In other words, it's done for you regardless if one uses a Model 1 or Model 2 approach.
-Graff
 
Roger Graff
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, apparently session tracking does not work with Model 1.
My application has a JSP that creates a user object, stores it in the session, then displays a list of hyperlinks to other JSPs. When the user clicks on a hyperlink, a new JSP is called and a different session is created.
In a nutshell, a session object is created for each entry point into the application.
Using model 1, many sessions are created since there are many entry points into the application.
Using model 2, only one session is created since there is only 1 entry point into the application.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no inherent reason for session tracking not to work in model 1 or 2. Note that sessions are only shared within a servlet context == web application. If all of your jsp and servlets are in the same web application they should be able to share a session.
Bill
 
Roger Graff
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by William Brogden:
There is no inherent reason for session tracking not to work in model 1 or 2. Note that sessions are only shared within a servlet context == web application. If all of your jsp and servlets are in the same web application they should be able to share a session.
Bill

I guess that's good news, but that's makes my bug even more odd. In the process of debugging, I displayed the jSessionID of each JSP and they are different.
Did I mention that when each hyperlink is clicked, a new browser is spawned? Perhaps some URL rewriting is in order....
 
Roger Graff
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Roger Graff:
[QB]Okay, apparently session tracking does not work with Model 1.

As usual, Bill is correct. Shame on me for jumping to conclusions!
My situation is unique and may require some manual cookie manipulation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic