Calling a URL with the help of HttpClient

Hi ,
You can call your jsp pages through HTTPClient .For that you just have to have commons-httpclient-*.jar.
Any version of this jar will work. For the below code i was having commons-httpclient-3.1.jar.

You can try the following lines to call your jsp page..
URL url = new URL("http://localhost/mywebapp/test.jsp"));
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(url.toString());
client.executeMethod(get);

Other way is to make some timeout settings in Connection.For that you have to modify some connection properties like this:

URL url = new URL("http://localhost/mywebapp/test.jsp");
HostConfiguration hcfg = new HostConfiguration();
hcfg.setHost(url.getHost(), url.getPort());
SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager();
HttpConnection connection = connectionManager.getConnection(hcfg);
HttpConnectionParams conparams = connection.getParams();
conparams.setSoTimeout(timeout);
conparams.setConnectionTimeout(timeout);

 HttpClient client = new HttpClient(connectionManager);
GetMethod get = new GetMethod( url  .toString());
client.executeMethod(hcfg, get);
//   Optional part for you to get the response  ---InputStream is = get.getResponseBodyAsStream();

Comments

Popular posts from this blog

Arrays.sort() and Collections.sort() NullPointerException

org.xml.sax. SAXParseException: Element type "web-app" must be declared.

Project facet Java 6.0 is not supported by target runtime JBoss