May 6, 2008

Calling Url using java servlet

This is the java code servlet block, to ping a servlet on URL.
Here we are using URLConnection class to open a connection.

System.err.println("@@W@Calling Test Servlet:: Called");
URLConnection uc = new URL("http://www.example.com/Test").openConnection();
uc.setDoInput(false);
uc.setDoOutput(true);
uc.setUseCaches(false);
uc.setDefaultUseCaches(false);
uc.setRequestProperty("Content-Type", "application/octet-stream");
ObjectOutputStream out = new ObjectOutputStream(uc.getOutputStream());
HashMap hm = new HashMap();
hm.put("Key1", "Val1");

out.writeObject(hm);
out.flush();
out.close();