Is this right .. How to call the servlet by java application

//program related to calling a servlet by java standalone application and printing the response on console

import java.io.*;

import java.util.*;

import java.lang.Object;

import java.net.*;

publicclass Program

{

publicstaticvoid main(String s[])

{

System.out.println("Hello this programm defines about how to call a servlet with a java application ");

try{

URL servlet =new URL("http://192.168.11.52:8080/anchor/studentform.html");

URLConnection conn=servlet.openConnection();

conn.setDoOutput(true);

InputStreamReader isr=new InputStreamReader(conn.getInputStream());

BufferedReader br =new BufferedReader(isr);

String str ;

while((str=br.readLine())!=null)

System.out.println(str);

}

catch(IOException e)

{

System.out.println("exception is" +e);

}

}

}

[1814 byte] By [saamera] at [2007-11-27 6:00:19]
# 1
I suspect not since http://192.168.11.52:8080/anchor/studentform.html is probably the url of a bit of static html and not the url of a servlet.
sabre150a at 2007-7-12 16:38:21 > top of Java-index,Java Essentials,New To Java...
# 2

Generally yes, except as mentioned the URL is probably not correct.

But I'm not sure the point of calling setDoOutput if you aren't going to. Setting this to true is (typically) only needed when doing a POST request.

You should probably be closing your input stream too, just to be thorough.

bsampieria at 2007-7-12 16:38:21 > top of Java-index,Java Essentials,New To Java...