• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use cookies with struts

 
zimbu bolleddu
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
Android Eclipse IDE Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic