Hi Markus,
<SUGGESTION>
Add all the objects to a vector (using addElement), and write the vector to the stream
using
outputToServlet.writeObject(vector).
</SUGGESTION>
I am not sure about the content type, may be some one else will help you out on that.
Hope this helps...
Bye.
-Kiran.
Markus Greunz wrote:
> Hi folks,
>
> I have a problem doing a doPost on a servlet from an applet. I open a
> URLConnection to the servlet and open an ObjectOutputStream to send
> data which should be processed in the doPost Method of the servlet. I
> also make a Reader to read the results of processing from the servlet.
> However, somwthing is wron with the connection since the service method
> of the servlet is not called and therefore also no doPost(). I enclose
> the applet code so maybe someone may have a look at it and can find the
> bug thats somwhere in there. I would be thankful for any hints!!
>
> Markus
>
> // establish connection to servlet and send the data
> try{
> // connect to servlet
> URL servletURL = new URL("http://localhost/MyServlet");
> URLConnection servletConnection = servletURL.openConnection();
>
> // set connection to in/out
> servletConnection.setDoInput(true);
> servletConnection.setDoOutput(true);
>
> // disable caching for URL connection
> servletConnection.setUseCaches(false);
> servletConnection.setDefaultUseCaches(false);
>
> // specify content type
> servletConnection.setRequestProperty("Content-Type",
>"application/octet-stream");
>
> // send the objects to the servlet using object serialization
> ObjectOutputStream outputToServlet = null;
> try{
> outputToServlet = new
>ObjectOutputStream(servletConnection.getOutputStream());
> outputToServlet.writeObject(obj1);
> outputToServlet.writeObject(obj2);
> outputToServlet.writeObject(obj3);
> outputToServlet.flush();
> outputToServlet.close();
> }
> catch(IOException e){
> System.out.println("error in writing to servlet: " + e.getMessage());
> }
>
> // read the input from the servlet
> BufferedReader inputFromServlet = null;
> try{
> inputFromServlet = new BufferedReader(new
>InputStreamReader(servletConnection.getInputStream()));
> String str;
> StringBuffer buf = new StringBuffer();
> while((str = inputFromServlet.readLine()) != null){
> buf.append(str);
> }
> inputFromServlet.close();
> textArea.setText(buf.toString());
> }
> catch(IOException e){
> System.out.println("error in reading from servlet: " +
>e.getMessage());
> }
>
> }
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html