Hi!
I'm using object serialization to communicate an applet to my servlet. I can
get data from my servlet and display it in my browser no problem so far.
However, sending data from the applet to the servlet it's more dificult
because it never enters in the doPost method of the servlet. The code in the
applet runs with no problem but it seems that the servlet don't recognize
the "post".
Here's my code:  Applet-side:

//FOR POST
try{
            URL url = new URL("http://localhost:8000/main";);
                   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(new String("OL�"));
                        outputToServlet.flush();
                        outputToServlet.close();
        }catch(Exception e){}

//FOR GET
try{
                        URL url = new URL("http://localhost:8000/main";);
                URLConnection con = url.openConnection();
                con.setUseCaches(false);
                InputStream in = con.getInputStream();
                ObjectInputStream objStream;
                objStream = new ObjectInputStream(in);
                Tipo_Servicos d = (Tipo_Servicos)objStream.readObject();

                textField1.setText(d.id_tipo.toString());
                textField2.setText(d.nome_servico);

                }catch(IOException o){o.printStackTrace();}
                catch(ClassNotFoundException c){c.printStackTrace();}
        }

My servlet code:


public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {

                   OutputStream out ;
                   ObjectOutputStream objStream;
                   out = response.getOutputStream();
                   objStream = new ObjectOutputStream(out);
                   Tipo_Servicos t = Tipo_Servicos.get_Tipos_Servicos();
                   objStream.writeObject(t);
                    Tipo_Servicos.insere_Tipos_Servicos("hugo", "viana");


    }

  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

                //Function to insert in database (If I put it in doGet it inserts)
            Tipo_Servicos.insere_Tipos_Servicos("hugo", "viana");

                ObjectInputStream inputFromApplet = null;
        Tipo_Servicos t = null;
        PrintWriter out = null;
        BufferedReader inTest = null;

        if(request.getParameter("opcao").equals("send")){
        try
        {

                inputFromApplet = new ObjectInputStream(request.getInputStream());

                String s = (String) inputFromApplet.readObject();
                inputFromApplet.close();
                //Database Insert values
                Tipo_Servicos.insere_Tipos_Servicos("hugo", s);

        }
        catch (Exception e)
        {
                        e.printStackTrace();
        }

        }

The function i use to insert in database works fine, because if i put in doGet it 
works fine, but in doPost it does nothing. That's why i think that it never enters in 
doPost.

Can you help me?
Sorry for this lonf e-mail and for your time. Thanks...
                                                                                Hugo 
Malheiro

___________________________________________________________________________
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

Reply via email to