wood burning stoves 2.0*
The moose likes Struts and the fly likes How to use cookies with struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to use cookies with struts" Watch "How to use cookies with struts" New topic
Author

How to use cookies with struts

zimbu bolleddu
Ranch Hand

Joined: Jan 14, 2008
Posts: 35
Hi all,

I'm new to struts, please let me know how to use cookies with struts.

I have three struts applications, in run time I have to switch from one application to another application based on single login page. I have taught cookies are one of the solution. But while I'm googling I unable to get such a good material.

please give some example,

Thanks in advance.
--------
zimbu
Robert Darling
Ranch Hand

Joined: Jun 21, 2008
Posts: 100

Hi,
rather then using cookies why dont you use session and then get and set function to retrieve and strore variables in the session.

Kind Regards,
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The HTTPSession won't work between different applications, since the J2EE specification mandates that different applications not share the same HTTPSession even if they're on the same server.

I'd suggest you just set a cookie with some sort of token indicating who the user is in your login action. Then have your other application check for the presence of this cookie. If it's not there, make them log in. If it is there, use the information in the cookie to get their information from a database, set it in the HTTPSession and let them continue.

Below is a link that shows you how to set and retrieve cookies. The sample code it gives is in a Servlet, but the same code could be used in a Struts Action as well.

http://www.devshed.com/c/a/Java/Saving-Client-State-with-Cookies-and-Java/
[ July 09, 2008: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use cookies with struts
 
Similar Threads
HttpSession when cookies are disabled
cookies="false" doesn't work in all cases
How to stop session cookies?
URL encoding in Struts with/without cookies
URL encoding in Struts is not working!