• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cookies in JSP

 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
Is it ok to set cookies through JSP, what exactly I am trying to achieve is, when the user visits the home.jsp page for the first time, a welcome note displaying "Welcome USER" is displayed, with other info on the homepage, after that if he posts his information on the site, I would like to store his user id in cookie, so that the other time he visits the same page, I will get his name from his id & display "Welcome <firstname>"...(something of the sort thats done on javaranch)...
tia
MB
 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
is the group dead, or am I not clear in asking the question...
MB
 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi..
Now that the authors are also going be over here, could they answer my query, I am really stuck at it & a bit confused too...
tia
MB
 
Timothy Stone
Ranch Hand
Posts: 71
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Malhar,
If your question is "Is it okay to set cookies in JSP?," I think the answer is "Yes."
Why you might not has some reasons however. One is that it puts Java code in the page and makes maintenance a bit troublesome down the road in a complex web application. However, if this is a simple application, then it's perfectly fine. MVC design here however is always best.
Also consider that you "add" Cookies, not "set" Cookies.
Tim
 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
When the first page to be loaded is in itself a JSP page, how would I go about using MVC design n retrieving the cookies. Would it be ok to "add" the cookie using a bean..??
bit confused on that...
tia
MB
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic