wood burning stoves 2.0*
The moose likes Servlets and the fly likes Sent data to different Application servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Sent data to different Application servlet" Watch "Sent data to different Application servlet" New topic
Author

Sent data to different Application servlet

sammeta Phanikumar
Ranch Hand

Joined: Oct 25, 2007
Posts: 81
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.


SCJP 5, SCWCD 5, SCDJWS 5
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

The best way will be to set the query string, like:


and in other app, access it like:


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
sammeta Phanikumar
Ranch Hand

Joined: Oct 25, 2007
Posts: 81
Sagar,

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

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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
    Marshal

    Joined: Mar 22, 2005
    Posts: 41800
        
      62
    How is the exact flow of control? Who is the client and who is the server for either request?


    Ping & DNS - my free Android networking tools app
    sammeta Phanikumar
    Ranch Hand

    Joined: Oct 25, 2007
    Posts: 81
    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
    Marshal

    Joined: Mar 22, 2005
    Posts: 41800
        
      62
    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

    Joined: Oct 25, 2007
    Posts: 81
    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
    Marshal

    Joined: Mar 22, 2005
    Posts: 41800
        
      62
    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

    Joined: Oct 25, 2007
    Posts: 81
    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
    Marshal

    Joined: Mar 22, 2005
    Posts: 41800
        
      62
    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

    Joined: Oct 25, 2007
    Posts: 81
    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
    Marshal

    Joined: Mar 22, 2005
    Posts: 41800
        
      62
    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

    Joined: Oct 25, 2007
    Posts: 81
    Thanks Ulf , I got it. I got it in an exmaple, but getting some error..will solve it.

    Thanks for all your help.

     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Sent data to different Application servlet