Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

cookies vs session

 
Ann Kanu
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 ?
 
William Brogden
Author and all-around good cowpoke
Rancher
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
 
Ben Dover
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!