When using URLConnection to upload an object from applet to servlet, the servlet's doGet method is never executed. Why?

Ana Narvaez

URL url=new URL("http://localhost:8080/servlet/ServerServlet?Action=3");
URLConnection servletConnection=url.openConnection();
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
servletConnection.setUseCaches (false);
servletConnection.setDefaultUseCaches (false);
servletConnection.setRequestProperty ("Content-Type", "application/octet-stream");
ObjectOutputStream outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
outputToServlet.writeObject("asdfa");
outputToServlet.flush();
outputToServlet.close();


I had the same problem and I resolved it reading the response from the servlet. You can do:
.....
outputToServlet.writeObject("asdfa");
outputToServlet.flush();
outputToServlet.close();

//and now read from the servlet
int code = servletConnection.getResponseCode();

//or you can read the header.
String header = servletConnection.getHeaderField(0);

//or you can obtain de inputstream
InputStream in = servletConnection.getInputStream();


I Hope this helps you
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact