(Yet Another) Applet-Servlet problem: doPost not being called when getOutputStream of servlet invoked.
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, November 5, 2001 06:14 AM

I'm not sure whether this query should go into the Applet, Servlet, or Tomcat Forum, so I've posted it here. I have implemented a client server Applet-Servlet communication structure, closely based on the excelent article by Chád Darby at http://www.j-nine.com/pubs/applet2servlet/Applet2Servlet.html At first I wanted to use the GenericServlet class (as a learning excercise) and found that reading a stream from the Servlet worked fine, but writing a stream didn't work. The applet wrote the data to the OutputStream (connected to my servlet) but the servlet did not react. ie the service() routine was not even called. Thinking that there was some magical parameter that I was overlooking I resorted to the httpServle   More>>

I'm not sure whether this query should go into the Applet, Servlet, or Tomcat Forum, so I've posted it here.

I have implemented a client server Applet-Servlet communication structure, closely based on the excelent article by Chád Darby at http://www.j-nine.com/pubs/applet2servlet/Applet2Servlet.html



At first I wanted to use the GenericServlet class (as a learning excercise) and found that reading a stream from the Servlet worked fine, but writing a stream didn't work. The applet wrote the data to the OutputStream (connected to my servlet) but the servlet did not react. ie the service() routine was not even called.


Thinking that there was some magical parameter that I was overlooking I resorted to the httpServlet class, and experienced the same thing.

That is that the doGet works, and the doPost is not even called.

I can't imagine that the information in the article is incorrect, since it seems to be the standard reference, so I must assume it is somewhere in my environment. Perhaps in the Tomcat setup?


I read a rumour here in one of the forums that data must be received from the applet, before it can be sent, but I had no joy there either.



Has anyone had a similar problem and already found a solution?

   <<Less

Re: (Yet Another) Applet-Servlet problem: doPost not being called when getOutputStream of servlet invoked.

Posted By:   Nathan_Bagby  
Posted On:   Wednesday, February 13, 2002 12:14 PM

Dear Steve,



Have you been able to resolve this? Its killing me! :)


I too am haveing a problem with doPost(). It seems the applet is
sending a request to the servlet/server but I get an EOFException when
attempting to read the response from the server/servlet. The buffer is
empty because the doPost() is not (being called?) or (not responding)?


I really need this to work. If you've resolved this can you provide some
pointers/sample code?



Would really appreciate your help!



Nathan

Re: (Yet Another) Applet-Servlet problem: doPost not being called when getOutputStream of servlet invoked.

Posted By:   Anonymous  
Posted On:   Tuesday, November 6, 2001 01:16 AM

When I first looked at your code, I thought "That is exactly what I'm doing". Then I noticed that there was one difference. You requested a response from the servlet after you did your post. I had tried doing a Get first then a Post, and it didn't work. Now I tried what you suggested, and did a Post, then a Get from the applet, and then it worked. It seems that the rumour that I read somewhere was right. I'll spell it out clearly for the search engine:


To establish an OutputStream from an Applet to a servlet, you must do a Post, followed by a Get. That is, first write to the input stream of the servlet, then read from the output stream of the servlet.


I read just one dummy byte (after posting my Object) and it worked


Does anyone know why?

Re: (Yet Another) Applet-Servlet problem: doPost not being called when getOutputStream of servlet invoked.

Posted By:   Shiva_dacherla  
Posted On:   Monday, November 5, 2001 09:54 AM

Hi,
Here I am putting some code. This code hits the Servlets dopost method. The approach for doget and dopost is little diffrent. Try this.


Thanks
Shiva

String str = http://" + hostName + ":" + port + servletPath
// send the groupHostList to the servlet using serialization
log("Sending the object to the servlet...");

// connect to the servlet
System.out.println("Connecting...");
URL url = new URL( str );
URLConnection servletConnection = url.openConnection();
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
servletConnection.setRequestProperty("Content-Type", "application/octet-stream");
// Don't use a cached version of URL connection.

servletConnection.setUseCaches(false);
servletConnection.setDefaultUseCaches(false);

outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
outputToServlet.writeObject(Object);
outputToServlet.flush();
outputToServlet.close();
object = readServletResponse(servletConnection);
log("Send Object is Complete.");

#########END#########

Note: Here the Object is any object you want to send. Just create some object and send it to the servlet and receives the response from the Servlet.
About | Sitemap | Contact