Apps
Apps

Reputation: 3389

How to pass data when redirecting from one web application to another?

I have two web application which are deployed in the same J2EE Application server. I need to redirect from one web application to another. Also I need to set some information in the Header from web application 1 so that it is available in web application 2. When I try to access the information which set in the header of Web App1 in Web App2, I'm getting "null". I'm using response.sendRedirect("http://localhost/webapp2") in Web Application 1 to redirect. Please help me to solve this.

Thanks, Apps.

Upvotes: 2

Views: 10321

Answers (3)

Arne Burmeister
Arne Burmeister

Reputation: 20594

A redirect is processed by the client (the browser). So only the client gets the headers you sent. The headers will not be passed to the webapp redirected to.

You can do one of the following things to pass information from one webapp to another:

  • pass data as request parameter
  • send data as cookie without path restriction
  • use cross context dispatching

A cookie received by the client will be send back to the server. The client does not know it is a different webapp. You just need to set the cookie path to /.

Cross context dispacthing is done by an internal forward in the container (use a RequestDispatcher from the ServletContext). The client will never know, the request is handled by another webapp. You than can set a request attribute to pass data. Cross context dispatching has to be enabled by the container for security reasons.

Upvotes: 8

oiavorskyi
oiavorskyi

Reputation: 2941

One of the options would be to simple pass information as GET attributes in the URL you used in sendRedirect call.

Upvotes: 0

letronje
letronje

Reputation: 9148

You could send the information as URL parameters.

Redirect to http://localhost/webapp2?param1=value1&param2=value2 ....

Upvotes: 1

Related Questions