aspose file tools*
The moose likes JSP and the fly likes cookies in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "cookies in JSP" Watch "cookies in JSP" New topic
Author

cookies in JSP

Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
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
SOA & Java Book
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
hi all
is the group dead, or am I not clear in asking the question...
MB
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
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

Joined: Aug 01, 2001
Posts: 71
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


Timothy Stone, MIT, SCJP
http://www.petmystone.com/
"This Satan's drink [coffee] is so delicious, we shall cheat Satan and baptize it." --Pope Clement the VIII (1592-1605)
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
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.
 
subject: cookies in JSP