Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can sendRedirect method hit a different server instance?

 
Soniya Chavan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain your question in more detail. I really have no idea what you are asking.
 
Soniya Chavan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to pass any information as request parameters on the URL.
 
Soniya Chavan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much for the reply.
Can I use the encodeRedirectURL method before sendRedirect to save the session parameters ??
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this perhaps an indication that your web apps are constructed incorrectly? Why the need to communicate between them?
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are there multiple instances? And why does data need to be shared among them?

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gokul Nanthakumar
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic