*
The moose likes Servlets and the fly likes Is session shared across JSPs in separate web applications? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Is session shared across JSPs in separate web applications?" Watch "Is session shared across JSPs in separate web applications?" New topic
Author

Is session shared across JSPs in separate web applications?

Kishore Kumar Reddy
Greenhorn

Joined: Aug 18, 2010
Posts: 7
Hi



I have a jsp(say,one.jsp) and it requests another jsp(say,two.jsp).From here, it is redirected to another jsp(say,three.jsp and this is in another web application.) one.jsp and two.jsp both are in another web application. and all together are in same web server(Tomcat).

The problem is, I inserted a value in session object in one.jsp. I am trying to retrieve this value from three.jsp.I am unable to get this value.

How can I get this value.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

You can't. Sessions are not shared across web applications.

If they need to be this closely tied, why are they separate web apps?

[I adjusted the title of this topic to better represent the question.]


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Can't we attach that object to a request object, and internally redirect it to the different web application in the same server?


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

What is the point of attaching a scoped variable to the request if you are about to do a redirect which cause the current request to terminate?
Kishore Kumar Reddy
Greenhorn

Joined: Aug 18, 2010
Posts: 7
How data can be shared between different web-applications?

For this, I felt a solution.That is data(for example,userID) sent to another web-app, append this data value as query string while redirecting to anothe web-app.

response.sendRedirect("/anotherWeb-App/recepient.jsp?queryString=userID");

In recepient.jsp, use request.getParameter("userID").

Is it the right solution?
Are there any better solution?
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Correct Bear! I'm wrong there! Thanks!

And, Kishore Kumar Reddy, with your method, we can only send String. What about other objects?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Again I ask, if they need to share data to this extent, is designing them as separate web apps the appropriate design?
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Bear Bibeault wrote:Again I ask, if they need to share data to this extent, is designing them as separate web apps the appropriate design?

So, there are no way to do this?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
"no way to do this?"

Not with a session object as managed by the server but there are plenty of ways to share information between web applications.

For example - serialized object with a unique ID stored in a data base or on disk.

Bill

Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

William Brogden wrote:"no way to do this?"

Not with a session object as managed by the server but there are plenty of ways to share information between web applications.

For example - serialized object with a unique ID stored in a data base or on disk.

Bill



Thanks, and it is possible only with the shared database?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Abimaran Kugathasan wrote:Thanks, and it is possible only with the shared database?


The two applications have to share data in some way. It doesn't specifically have to be an SQL database.
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Paul Clapham wrote:
The two applications have to share data in some way. It doesn't specifically have to be an SQL database.


I got it, thanks!
Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 147

Depending on how much data, and how sensitive the data is, a simple solution might be to use the javax.servlet.http.Cookie object. You may need to have to make the cookie work site wide (as opposed to just under the current directory or context).

I would only do this for a small amount of non-sensitive data. if you have a lot of data, or it contains sensitive information, I'd also advocate the single web application idea that several commentators have already hit on.


OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
 
jQuery in Action, 2nd edition
 
subject: Is session shared across JSPs in separate web applications?