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

Sessions

 
Sandeep Jindal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know sessions use cookies.
But in my appliaction when i access my appliaction, i found no cookies on my machine...
and if the cookies are disables, will he sessions be managed automatically th' urlrewriting
 
Sri Basavanahally
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sandeep !
You have to rewrite(in other words it is not automatic) your URLs using encodeURL method in your application. This will ensure session tracking even when cookies are disabled.
-Sri
 
Sandeep Jindal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello sri,
Thanks for ur reply....
But i still have two doubts...
1) Since I am using sessions, that means defaulty I am using cookies(is it right to say), so my cookies folder in windows must have some file describing the sessions. But it is not there.
2) If my cookies are disable in a browser, wont i be able to access the session part of my application.
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sandeep
Yes, the default way to manage sessions is through cookies. If cookies are disabled on the client browser then you have to manually call encodeURL() and pass it the URL to write out to the browser. Something like this:

This assumes that out is a valid PrintWriter and resp is a valid HttpServletResponse.
For your first question, there might not be any cookies stored if you never created a session. Did you use HttpServletRequest.getSession(true) to get/create a session? Dont forget that you ahve to get the Session object before writing to the client.
Hope this helps
 
Sandeep Jindal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dave,
But my application always uses sessions, infact one every page i display 2-3 componenets from sessions only. But in cookies folder I deleted all the cookies, and when I run my aplication(browswer), there was no new cookies.
But i noticed one thing that in cookies folder there is a file index.dat, that changes whenever a new session creates(e.g.clicking first time after webserver opens).
So is the index.dat resposible for maianting sessions and if yes then what bout the cookies.
If not then where the cookies are stored?
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sandeep
I dont know what index.dat is, did you try to open it in notepad or another text editor to see what was in it?
As far as the cookies not showing up in your cookies folder or in your temp internet files folder that is most likely because the cookie is set to expire right away so your system never stores them. I would bet that your browser never even writes them to your hard drive. Is there something specific you want to do with the cookies or were you just trying to see them in action?
 
Sandeep Jindal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dave...
But our discussion moved to other way..
My question was: There is an application running on a webserver. That application uses sessions(I am storing and retriving some data from session object). When i access this apliaction from other machine say A, then there must be some cookies stored in the cookies folder of machine A.(as cookies is the default method to use sessions). But my problem is that i found no cookies saved on A.
So I wanted to know why the cookies not saving? or if it is saving somewehere else, then where is it(Like index.dat)
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpSession uses transient cookies. They are stored in memory and in in some folder. When the browser is closed the cookie dies because it is transient.
If you want to use persistent cookie uwe the Cookie class. Refere the docs for more info.
 
Sandeep Jindal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Pradeep,
Thanks a lot for ur answer. I never heared bout the transient cookies. Can I get more bout this.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic