aspose file tools*
The moose likes JSP and the fly likes Can sendRedirect method hit a different server instance? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Can sendRedirect method hit a different server instance?" Watch "Can sendRedirect method hit a different server instance?" New topic
Author

Can sendRedirect method hit a different server instance?

Soniya Chavan
Greenhorn

Joined: May 10, 2010
Posts: 7
I need to the session information in the target jsp. Is is possible that the sendRedirect method can hit the target jsp on another instance of the server??
What will be the alternative method in this case id I need to make sure that the same server instance is being hit??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61198
    
  66

Please explain your question in more detail. I really have no idea what you are asking.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Soniya Chavan
Greenhorn

Joined: May 10, 2010
Posts: 7
I am sorry I did not elaborate.

I am using sendRedirect method to forward the request from source to another jsp (target.jsp). In the target.jsp I need to access the session parameters.

Now these jsp's are a part of my application which is deployed on 2 instances of the server.Since sendRedirect makes a new request and sendRedirect can be used to forward to resources not within the same context. Is it possible that the source and the target may not reside on the same server instance?? and that the sendRedirect can forward the request to target.jsp of another server instance.
Soniya Chavan
Greenhorn

Joined: May 10, 2010
Posts: 7
And if the target.jsp of another server instance (not the same server instance of the source) is being hit....The target.jsp will not have the session parameters.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61198
    
  66

You'll need to pass any information as request parameters on the URL.
Soniya Chavan
Greenhorn

Joined: May 10, 2010
Posts: 7
Thank you so much for the reply.
Can I use the encodeRedirectURL method before sendRedirect to save the session parameters ??
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Really, if your application is running on more than one server, and sessions aren't being shared among those servers, there is no point in using sessions at all. You would have to pass the relevant information around as request parameters, like Bear suggested.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61198
    
  66

Is this perhaps an indication that your web apps are constructed incorrectly? Why the need to communicate between them?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

It sounds to me like there's only one application, and there is more than one instance of it running on more than one server. And that sessions aren't being shared among the servers. I would definitely describe that as "constructed incorrectly" and I would work on getting that fixed rather than trying to work around it with programming.

But it's possible I am misunderstanding the background to the question.
Soniya Chavan
Greenhorn

Joined: May 10, 2010
Posts: 7
First of all thanks a lot Paul and Bear.

Yes Paul you are right.There is a single application but more than one instance of the application.So the best way to solve this problem is to share the session among all the instances ??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61198
    
  66

Why are there multiple instances? And why does data need to be shared among them?

Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Soniya Chavan wrote:First of all thanks a lot Paul and Bear.

So the best way to solve this problem is to share the session among all the instances ??


Session replication is one solution.
Another would be to use sticky sessions at the router/load balancer (probably the simplest if your router can do this).
Another would be to make the instances stateless (no session data).

The 'best' solution depends on a lot of things.
Folks on a web forum are probably not in the best determination to make that call for you.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Gokul Nanthakumar
Ranch Hand

Joined: May 11, 2010
Posts: 56
The solution is depends upon the setup of our instances,

1. if the instances are in clustering with session replication, no need of any fix from code, hitting any of the instances will not make any differences
2. if the instances are not in clustered session replication and the redirection of the requests are happening from a load balancer, usually only the first request from the client will hit loadbalancer and the subsequent requests and redirect will hit the same instance, its like loadbalancer is doing one time redirecting to one instance.
3. if the instance are not in clustered session replication and the redirection is happening from a load balancer for every request, then this setup need to be fixed not the program.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can sendRedirect method hit a different server instance?