• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

cookies vs session

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When should we opt to use a session and when should we use oookies in an application. What are the main differences between the two.
And if cookies are turned off in a browser, do we need to call response.encodeUrl() explicitly or is it automatically taken care of ?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

When should we opt to use a session and when should we use oookies in an application. What are the main differences between the two.


Cookies are intended to hold short strings of text on the user's browser while sessions can hold any Java object on the server.

And if cookies are turned off in a browser, do we need to call response.encodeUrl() explicitly or is it automatically taken care of ?


Any encoding of URLs to hold session ids must be done explicity.
The third approach is to use hidden values in Forms instead of cookies.
Bill
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Holding state in sessions can be more performant than cookies, especially if you have large amounts of data, and is easier to pass around to other parts of your app. Cookies can only hold so much info. Consider holding sate info in the request object as well if only the next request needs it.
 
Marshal
Posts: 67339
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cookies can also be used to hold (short) data that must have a lifetime extending across sessions.
 
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!