File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

servlet to servlet and back??

Jason Lee

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 = "";
URL testJSP = new URL(jspLocation);
HttpURLConnection httpConnection =
httpConnection.setRequestProperty("Content-type", "text/html");
httpConnection.setRequestProperty("stringName", "StringToSend");
BufferedInputStream bis = new

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.


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

Joined: Feb 05, 2001
Posts: 17249

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.


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

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

and the second
I agree. Here's the link:
subject: servlet to servlet and back??
Similar Threads
applet to servlet
Make a Servlet or JSP relinquish control
calling another servlet using HttpURLConnection class
servlet redirection
Accessing servlets using URLConnection