Results 1 to 1 of 1
- 04-01-2009, 05:12 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 1
- Rep Power
- 0
Servlet to Servlet connection through URLConnection
Hi guys,
I have a servlet(Servlet1) which should open URLConnection to another servlet(Servlet2) and read the response from Servlet2.
I did the following but i got null response. please please help me
URL parURL = new URL("Another Servlet URL");
HttpURLConnection urlConnection =
(HttpURLConnection) parURL.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setRequestProperty("Content-type", "application/x-www-form-urlenCcoded");
urlConnection.setAllowUserInteraction(true);
urlConnection.connect();
System.out.println("1");
StringBuffer sb = new StringBuffer();
InputStream in=null;;
try {
in =
((HttpURLConnection) urlConnection).getInputStream();
} catch (Exception ex) {
System.out.println("Exception:"+ex.getStackTrace() );
}
int length = urlConnection.getContentLength();
System.out.println("2");
for (int n = 0; n < length; n++) {
sb.append((char) in.read());
}
System.out.println("String Buffer Content:"+sb.toString());
Please help me ASAP ...
Thanks
Sudarshan
Similar Threads
-
Servlet - apache tomcat/glassfish server shuts down on servlet usage
By StewS in forum Java ServletReplies: 1Last Post: 12-02-2008, 01:23 AM -
Is there any way to transfer the file Streams from one servlet to another servlet .
By HenaPriyadarsini in forum Java ServletReplies: 0Last Post: 08-30-2008, 12:52 PM -
my first servlet
By sireesha in forum Java ServletReplies: 3Last Post: 04-09-2008, 04:11 PM -
Regarding Servlet
By Sudha in forum New To JavaReplies: 1Last Post: 02-12-2008, 01:44 AM -
javax.servlet.ServletException: Wrapper cannot find servlet class util.t2
By osval in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 04:47 PM
Bookmarks