1

I have two applications based out of struts 1.3 frame work and deployed onto glassfish server 3.1.2

app-1 has its own url http:localhost:8080/app-1

&

app-2 has its own url http:localhost:8080/app-2

Functionality: app-1 & app-2 supports various languages. User log's in through app-1 and a cookie is setup for language selected.

Later, there are several href's to app-2 from app-1. The href's are more generic. After reaching app-2 based on language selected at app-1 various pages are displayed.

The issue is, how will app-2 know what is the language selected in app-1 ? How too get cookie set by app-1 to app-2 ? Or is there any other option ?

zion_ck
  • 53
  • 2
  • 12

2 Answers2

2

Set path attribute in Cookie to / while creating cookie. Servlet 3.0 provides the API for setting cookie attributes by application.

If Path (which the application context root) is set, the cookies are sent only if the url starts with that path. Setting it to / will enable the browser to send the cookies for all application within that domain.

Java Doc : setPath ......

public void setPath(java.lang.String uri)
Specifies a path for the cookie to which the client should return the cookie.

The cookie is visible to all the pages in the directory you specify, and all the pages in that directory's subdirectories. A cookie's path must include the servlet that set the cookie, for example, /catalog, which makes the cookie visible to all directories on the server under /catalog.

Consult RFC 2109 (available on the Internet) for more information on setting path names for cookies.

Parameters: uri - a String specifying a path

Ramesh PVK
  • 15,200
  • 2
  • 46
  • 50
0

It seems that a cookie set for a different path cannot be accessed, even when it is in the same domain, for security reasons:

https://stackoverflow.com/a/1968108/1916098

You may try another approach: If the two servlets share the same context you can use it (ServletContext) for sharing information between them. Look at this:

How can I share a variable or object between two or more Servlets?

Community
  • 1
  • 1
Kurt
  • 36
  • 3
  • This won't be a right approach if servers are in different environments. The best bet will be using a query string parameter. – Luiggi Mendoza Mar 27 '13 at 02:42