Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What is a session  RSS feed

 
Steve Dyke
Ranch Hand
Posts: 1739
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help to make sure I understand Web App development.

My web app sets on our server.

User 1 accesses the app index.jsp through url address.
The jsp requests a servlet which does session.setAttribute("user","Steve")

now if

User 2 accesses the app index.jsp through url address.
The jsp requests a servlet which does session.setAttribute("user","John")

Does this affect User 1 at all? Or are session attributes unique to that particular users instance of the web app?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, sessions are per user.

There is a link to the servlet spec in my signature.
If you download it, you'll find a very complete and easy to understand description of sessions in Java web applications.
 
Steve Dyke
Ranch Hand
Posts: 1739
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sure glad to hear that. I am learning web development as I go and sometimes when thigs are not reacting as normal I need to find out if I am still on the right track.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're learning servlets, you should have the Servlet, JSP, and JSTL specs right on your desktop.
 
Qussay Najjar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Steve Dyke:
I need help to make sure I understand Web App development.

My web app sets on our server.

User 1 accesses the app index.jsp through url address.
The jsp requests a servlet which does session.setAttribute("user","Steve")

now if

User 2 accesses the app index.jsp through url address.
The jsp requests a servlet which does session.setAttribute("user","John")

Does this affect User 1 at all? Or are session attributes unique to that particular users instance of the web app?


With every user logs in, a new session scope will be created for him/her.
this session has a session id that makes sure no other user would have the same information on the session scope.
 
Steve Dyke
Ranch Hand
Posts: 1739
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok next question.

My first servlet request(say MainServlet), in the doPost method I have:
HttpSession session = arg0.getSession(true);

My my second servlet request(say DrawingData), in the doPost method I also have:
HttpSession session = arg0.getSession(true);

I this ok. I realize that arg0 is not very descriptive but my concern is the session code.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You get the session from the request object that is passed to your doGet or doPost method.
 
Steve Dyke
Ranch Hand
Posts: 1739
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So does this mean I have two sessions? If in the first servlet where I have the HttpSession session = arg0.getSession(true) I said session.setAttribute("v1","Steve") Then in my second servlet I did the HttpSession session = arg0.getSession(true) does this affect the attribute set in the first servlet?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should really take a few minutes to read the section in the spec on sessions (10 to 15 minute read).

The short answer is no.
Each user has one session object on the server at a time.

As long as it doesn't expire from lack of use, they don't close their browser, or execute code that invalidates it, they will keep that session indefinately, no matter how many requests they make and how many different pages, servlets, whatever they hit within that web application.
 
Steve Dyke
Ranch Hand
Posts: 1739
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to clarify the post 86207 that you just answered with your post. The question in post 86207 is concerning one user making two requests with in the same app.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Steve Dyke:
I want to clarify the post 86207 that you just answered with your post. The question in post 86207 is concerning one user making two requests with in the same app.


86207 is your member id.

What question do you need answered?
[ January 18, 2008: Message edited by: Ben Souther ]
 
Steve Dyke
Ranch Hand
Posts: 1739
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry the number of the post was actually my member number, I was not paying attention. Can you look at 4 post back including this one(unless someone else makes a post).
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see it.
What don't you understand about it?

Did you read the section in the spec on sessions?
Did it help?


Also, there is a quote feature in UBB, Just click the icon in a particular post and it will start a new one with the contents marked as a quote.
That's a lot more effective than trying to count up a specified number of posts.
[ January 18, 2008: Message edited by: Ben Souther ]
 
Steve Dyke
Ranch Hand
Posts: 1739
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
You should really take a few minutes to read the section in the spec on sessions (10 to 15 minute read).

The short answer is no.
Each user has one session object on the server at a time.

As long as it doesn't expire from lack of use, they don't close their browser, or execute code that invalidates it, they will keep that session indefinately, no matter how many requests they make and how many different pages, servlets, whatever they hit within that web application.



I learn more everytime I use this forum and is a great help. Yest I did read the Spec and it has helped.

This was my post:

So does this mean I have two sessions? If in the first servlet where I have the HttpSession session = arg0.getSession(true) I said session.setAttribute("v1","Steve") Then in my second servlet I did the HttpSession session = arg0.getSession(true) does this affect the attribute set in the first servlet?

In your response I wanted to make sure you realized that this is one user making two requests. The earlier posts were dealing with multiple users.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did understand that.
Sessions and users have a 1 to 1 relationship.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!