aspose file tools*
The moose likes Servlets and the fly likes servlet to   servlet and back?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet to   servlet and back??" Watch "servlet to   servlet and back??" New topic
Author

servlet to servlet and back??

Jason Lee
Greenhorn

Joined: Jul 23, 2001
Posts: 15
Hello all,

Question for you experts.
I have 2 servlets. Servlet1 send Strings to servlet2. Servlet2 does stuff, then should send it back to servlet1.

servlet1 code:

String jspLocation = "http://xxx.xxx.xxx.xxx:8080/servlet2";
URL testJSP = new URL(jspLocation);
HttpURLConnection httpConnection =
(HttpURLConnection)testJSP.openConnection();
httpConnection.setDoOutput(true);
httpConnection.setDoInput(true);
httpConnection.setRequestMethod("POST");
httpConnection.setUseCaches(false);
httpConnection.setRequestProperty("Content-type", "text/html");
httpConnection.setAllowUserInteraction(false);
httpConnection.setRequestProperty("stringName", "StringToSend");
BufferedInputStream bis = new
BufferedInputStream(httpConnection.getInputStream());
bis.close();

Servlet2:
I simply get the value of 'stringName' by using:

String strName = request.getHeader("stringName");
String newStrName = strName + "new string name";

How do I go about returning the value of 'newStrName' to Servlet1?

Is it simply a matter of using the response object or...?

Thanks in advance for your help.

Jason

[ June 07, 2004: Message edited by: Jason Lee ]
[ June 07, 2004: Message edited by: Jason Lee ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

I thought you would use the response object and send it through the OutputStream. the same as if you were sending it back to a browser.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
rick zorich
Greenhorn

Joined: Aug 31, 2003
Posts: 16
Here are two JSPs that I wrote a while ago. You could use same idea.
------sender.jsp----------------------------------------------

and the second
----------------------bouncer.jsp----------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlet to servlet and back??