Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet request a page?  RSS feed

 
Varek Boettcher
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can a servlet make an http request another page or servlet on the same web server it's running on? I know this may seem like a silly/strange question but we're trying to do two things on the server with one request.
Thanx for any help!
------------------
Varek Boettcher
 
Brian Nice
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using the URL connection classes. You can do something like the following in your servlet to send a request to another servlet and get the response back:
urlString = "http://www.someurl.com/servletpath?param1=parm";
URL url = new URL(urlString);
URLConnection con = url.openConnection();
con.setDoInput(true);
con.setDoOutput(false);
con.setUseCaches(false);

InputStream is = con.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = null;
int linesRead = 0;
while ( (line = br.readLine()) != null) {
++linesRead;
}
Does this help?
Brian
 
Varek Boettcher
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it does... Thanx much!

------------------
Varek Boettcher
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!