Ike said:
Post us some code so we can see what your problem is!
-Ike
Thanks for response, here I have a simple code for you I hope you are
gonna be able to catch the bug or find the issue.
// this ia a method of applet sendin the data (String) to servlet.
public void sendData () {
try {
// the following servlet is mapped on the server in
TomCat.
URL url = new
URL("
http://localhost:8080/myServlet?p1=abc&p2=def&p3=ghi");
URLConnection urlCon = url.openConnection();
// inform the connection that we will send output and
accept input
urlCon.setDoInput(true);
urlCon.setDoOutput(true);
// Don't use a cached version of URL connection.
urlCon.setUseCaches(false);
urlCon.setDefaultUseCaches(false);
// Specify the content type that we will send binary data
urlCon.setRequestProperty("Content-Type",
"application/octet-stream");
// sending the data
ObjectOutputStream outputToServlet = new
ObjectOutputStream(urlCon.getOutputStream());
outputToServlet.writeObject("This is a primitve
serializable object (String)");
outputToServlet.flush();
outputToServlet.close();
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex1) {
ex1.printStackTrace();
}
}
this the servlet very simple
class myServlet extends HttpServlet {
public void doGet (HttpServletRequest request,
HttpServletResponse response) throws
IOException, ServletException {
doPost(request, response);
}
public void doPost (HttpServletRequest request,
HttpServletResponse response) throws
ServletException,
IOException {
try {
// get an input stream from the applet
ObjectInputStream inputFromApplet = new
ObjectInputStream(request.getInputStream());
// read the serialized data from applet
String str = (String) inputFromApplet.readObject();
inputFromApplet.close();
// out put to console
System.out.println("DEBUG: " + str);
// out put to tomcat log
log("DEBUG: " + str);
} catch (IOException IOe) {
System.out.println("DEBUG: doPost()" +
IOe.getMessage());
} catch (ClassNotFoundException ex) {
System.out.println("DEBUG: doPost()" +
ex.getMessage());
}
}
}