Hello,

I have an applet that sends a vector to a servlet and
gets a new vector from the servlet in return -- if
that's the type of thing you need take a look at the
code snipit below:

private Vector InitiateReport()
  {
        ObjectInputStream inputFromServlet = null;
        Vector tempVector = null;

    try
    {
      URL hostURL = hra_applet.urlCodeBase;
      URL servletPOST = new URL("http://" +
hostURL.getHost() + ":" + hostURL.getPort() +
"/servlet/web_hra_servlet");

      URLConnection con =
servletPOST.openConnection();
      con.setDoInput(true);
      con.setDoOutput(true);
      con.setUseCaches(false);
      con.setRequestProperty("Content-Type",
"application/octet-stream");

      try
      {
        ObjectOutputStream outputToServlet = new
ObjectOutputStream(con.getOutputStream());
        String request = new String("InitiateReport");
        Vector vct = new Vector(4);
        vct.addElement(request);
        vct.addElement(Integer.toString(Index));
        vct.addElement(new String(answerArray));
        vct.addElement(UserInfo);
        outputToServlet.writeObject(vct);
        outputToServlet.flush();
        outputToServlet.close();
      }
      catch(IOException e)
      {
                  System.out.println("Error sending to servlet in
InitiateReport:  " + e);
                  e.printStackTrace();
      }

      inputFromServlet = new
ObjectInputStream(con.getInputStream());
      try
      {
        tempVector =
(Vector)inputFromServlet.readObject();
      }
      catch(IOException e) { System.out.println(e);
e.printStackTrace(); }
      catch(ClassNotFoundException e) {
System.out.println(e); e.printStackTrace(); }
      catch(Exception e) { System.out.println(e);
e.printStackTrace(); }

          inputFromServlet.close();


        return tempVector;
  }


--- Rashid Mohiuddin <[EMAIL PROTECTED]> wrote:
> Thanks Jim,
>   But I've already done this, and I am calling the
> servlet without any parameters. Actually, I just
> wanna transfer some data from the client to server.
> And it seems that applet is getting some problem in
> opening the outputstream with the servlet (i.e. from
> applet to servlet transfer), because I am successful
> in transfering the data from servlet to applet.
>
> any idea about this?
>
> Regards,
>
> Rashid.
>   ----- Original Message -----
>   From: Jim Richards
>   To: [EMAIL PROTECTED]
>   Sent: Monday, November 22, 1999 11:02 AM
>   Subject: Re: Please Help: Applet-Servlet
> communication
>
>
>   At 10:36 AM 22/11/99 +0800, you wrote:
>
>     Hello Everybody,
>          I am trying to pass some data from client
> side to server through applet-servlet communication.
> But I am unable to develop the connection between
> them. I've seen examples/books on this issue and
> everything seems to be fine.
>     The interesting thing is that when I access the
> Servlet URL  directly with the browser, I succeed in
> entering the doPost method. But when i open the same
> URL with the applet, I get the following result on
> the server side
>
>   If you are calling the URL like
>
>
>
http://www.myhost.com/servlet/MyServlet?name=value&name2=value2
>
>   then this is a doGet method of calling the servlet
> ... not a doPost. Easiest solution
>   is for your servlet code to have
>
>           public void doGet(HttpServletRequest
> request, HttpServletResponse response) throws
> ServletException, IOException {
>                   doPost(request, response);
>           }
>
>
>
>
>     1-  a NullPointerException on the
> "ServletFactory"
>     2- a Connection refused error on the "Weblogic"
>
>     It seems that applet-call is not even entering
> the doPost() method of the Servlet.
>
>     I'll highly appreciate if somebody could help me
> with that.
>
>
>     Thanks in advance,
>
>     Rashid.
>
>
>
>
>   --
>   Subvert the dominant paradigm
>   http://www.cyber4.org/members/grumpy/index.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
>


=====
------------------------------------------------------------
James Wilson
HealthFirst Corporation
[EMAIL PROTECTED]
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

___________________________________________________________________________
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