This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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
Make a Servlet or JSP relinquish control
calling another servlet using HttpURLConnection class
Accessing servlets using URLConnection
servlet redirection
applet to servlet