Hi ...
thx for reply..
program is working now...
actually i was trying break the connection establishment function ,write to stream function and reading response function.
somewhere it went wrong and i was getting that problem.
The simplest code will be..
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.net.*;
public class TestingServlet extends HttpServlet
{
public void init(ServletConfig config)
throws ServletException
{
System.out.println("once done");
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
{
URLConnection con;
try
{
con = getConnection("http://ipaddress:8080/servlets-examples/servlet/TestingServletServer");
writeToServlet(con);
Boolean result = readFromServlet(con);
con = getConnection("http://ipaddress:8080/servlets-examples/servlet/TestingServletServer2");
writeToServlet(con);
Boolean result2 = new Boolean(true);
result2 = readFromServlet(con);
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Servlet
Testing</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("Welcome to the Servlet Testing Center"+result+"\t"+result2);
out.println("</BODY>");
out.println("</HTML>");
System.out.println("RESULT "+result+"RESULT 2 "+result2);
}
catch(Exception e)
{
System.out.println("Exception caught "+e);
}
}
private void writeToServlet(URLConnection con)
{
try
{
ObjectOutputStream oos=new ObjectOutputStream(con.getOutputStream());
oos.writeObject(new Boolean(true));
oos.flush();
oos.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
private Boolean readFromServlet(URLConnection con)
{
Boolean result = null;
try
{
ObjectInputStream ois=new ObjectInputStream(con.getInputStream());
result = (Boolean)ois.readObject();
}
catch(Exception e)
{
System.out.println(e);
}
return result;
}
private URLConnection getConnection(
String RL)
{
URLConnection con = null;
try
{
URL url = new URL(RL);
con = url.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
}
catch(Exception e)
{
System.out.println(e);
}
return con;
}
}
code for TestingServletServer
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class TestingServletServer extends HttpServlet
{
public void init(ServletConfig config)
throws ServletException
{
System.out.println("once done");
}
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
doGet(req,res);
}
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
try
{
System.out.println("inside doGet");
res.setContentType("Application/Octect-Stream");
ObjectInputStream ois=new ObjectInputStream(req.getInputStream());
Boolean result = (Boolean) ois.readObject();
ObjectOutputStream oos=new ObjectOutputStream(res.getOutputStream());
oos.writeObject(new Boolean(true));
oos.flush();
oos.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
code for TestingServletServer2
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class TestingServletServer2 extends HttpServlet
{
public void init(ServletConfig config)
throws ServletException
{
System.out.println("once done 2");
}
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
doGet(req,res);
}
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
try
{
System.out.println("inside doGet 2");
res.setContentType("Application/Octect-Stream");
ObjectInputStream ois=new ObjectInputStream(req.getInputStream());
Boolean result = (Boolean) ois.readObject();
ObjectOutputStream oos=new ObjectOutputStream(res.getOutputStream());
oos.writeObject(new Boolean(false));
oos.flush();
oos.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}