File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Receiving response from another server program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Receiving response from another server program" Watch "Receiving response from another server program" New topic
Author

Receiving response from another server program

Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
Is it possible to write a Servlet that will send request to some PHP page and then read the response generated by that PHP page? Response should contain attached "doc" file. Receiving that "doc" file is what I'm interested in.
Is there any guidelines on how to do such thing?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Have a look at http://jakarta.apache.org/commons/httpclient


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

Joined: Oct 12, 2000
Posts: 5093
Or just use HttpURLConnection...


42
Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
and then what?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Write your application.
Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
I don't even need HttpURLConnection in order to open a stream to the specified .doc file on the Internet if I know its absolute URL address.

But, in this case I have an PHP page that dinamically generates .doc file as a byte stream I want my servlet to record that stream. I'm not sure what datas I have to read before the stream starts, i.e. I don't know where the stream begins.?
Note: When I use browser, PHP response causes my browser to popup the "Save As" dialog.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Go read the documentation for HttpClient. It will allow you to simulate everything that a browser does from within your servlet code.
You could also retrieve it using the HttpUrlConnection as Jeroen mentioned.

Once you get it into your servlet, you can do whatever you want with it.
Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
OK. Gonna try it.
 
 
subject: Receiving response from another server program