• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sent data to different Application servlet

 
sammeta Phanikumar
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

"I want to send some parameters to a servlet which is in different web application"

I am sorry, gone through many threads on this but in most of them are given solutions to share data in the same application using headers/request attributes etc.

So please give me a solution how it is possible between web applications.

Here how am trying now...

In Application1 , Servlet 1 :

response.setHeader("Key","value");
response.sendRedirect("New Application URL");
In Applicatino2, Servlet 2:
request.getHeader("key")

But it is not giving the header which am sending.

So please let me know where am wrong help in this.
thanks in advance.

 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way will be to set the query string, like:


and in other app, access it like:

 
sammeta Phanikumar
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sagar,

Thanks for your reply, but i do not want to append the parmeters.

 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Header fields are for the browser, so that they can underrated and process the response accordingly. So I don't think this header thing gonna work.

There are only two methods for your requirement:
  • Query string.
  • Session object, if both app are in same context
  •  
    Ulf Dittmer
    Rancher
    Posts: 42967
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    How is the exact flow of control? Who is the client and who is the server for either request?
     
    sammeta Phanikumar
    Ranch Hand
    Posts: 81
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Here is the flow.

    App1[JSP->Servlet1] -------------->App2[ servlet2]

    Both applicaiton are developed in java. From the jsp i will input values..i read them and have to send them Servlet2.

    I don want to send directly from JSP -> servlet2 and I dont want to append input values to URL.


     
    Ulf Dittmer
    Rancher
    Posts: 42967
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    So servlet 1 calls servlet 2; should the output of servlet 2 go back to the browser, or should servlet 1 do something with the output of servlet 2 and then send a response back to the browser?
     
    sammeta Phanikumar
    Ranch Hand
    Posts: 81
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Once the request is sent to App2/Servlet2 then no reply is expected back to App1/Servlet1.

    But my testin purpose am trying to display the all headrs from servlet2....there i could not see the headers which I set in Servlet1.

     
    Ulf Dittmer
    Rancher
    Posts: 42967
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    A client-side redirect causes a 2nd request from the browser to the 2nd server - with a new set of headers that are unrelated to the headers used in the 1st request. You may wish to read up on HTTP's request/response mechanism and how a client-side redirect works in your favorite servlet/JSP book/tutorial.
     
    sammeta Phanikumar
    Ranch Hand
    Posts: 81
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Ulf,

    If this mechanism is a client side redirection does sent new set of request,response then ok ...my headers are not sent. Then please tell me is there any other way to send set of parameters as part of HTTP etc.

     
    Ulf Dittmer
    Rancher
    Posts: 42967
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Servlet 1 can use the HttpURLConnection class (or, easier to use, the Apache HttpClient library) to make a call to servlet 2.
     
    sammeta Phanikumar
    Ranch Hand
    Posts: 81
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Ulf,
    I gone through some of the examples with HttpClient, Here it used to have a sessino with other applicaiton.

    but i just want to send some parameters either as parameters or headers from Servlet1 --> Servlet2.

    Please help me with some code lines .....

     
    Ulf Dittmer
    Rancher
    Posts: 42967
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I gone through some of the examples with HttpClient, Here it used to have a sessino with other applicaiton.

    I don't understand what that has to do with this topic.

    but i just want to send some parameters either as parameters or headers from Servlet1 --> Servlet2.

    The HttpClient examples show how to do that, don't they? What do you have so far, and what's still missing to make it work?
     
    sammeta Phanikumar
    Ranch Hand
    Posts: 81
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Ulf , I got it. I got it in an exmaple, but getting some error..will solve it.

    Thanks for all your help.

     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic