This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet to servlet and back??

 
Jason Lee
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
rick zorich
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are two JSPs that I wrote a while ago. You could use same idea.
------sender.jsp----------------------------------------------

and the second
----------------------bouncer.jsp----------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic