HTTP POST
--WRITE To Applet--
      String protocol = currentPage.getProtocol();
      String host = hostField.getTextField().getText();
      String portString = portField.getTextField().getText();
      int port;
      try {
        port = Integer.parseInt(portString);
      } catch(NumberFormatException nfe) {
        port = -1; // I.e., default port of 80
      }
      String uri = uriField.getTextField().getText();
      URL dataURL = new URL(protocol, host, port, uri);
      URLConnection connection = dataURL.openConnection();
         // POST requests are required to have Content-Length
      String lengthString =
        String.valueOf(byteStream.size());
      connection.setRequestProperty
        ("Content-Length", lengthString);

      // Netscape sets the Content-Type to multipart/form-data
      // by default. So, if you want to send regular form data,
      // you need to set it to
      // application/x-www-form-urlencoded, which is the
      // default for Internet Explorer. If you send
      // serialized POST data with an ObjectOutputStream,
      // the Content-Type is irrelevant, so you could
      // omit this step.
      connection.setRequestProperty
        ("Content-Type", "application/x-www-form-urlencoded");

      // Write POST data to real output stream
      byteStream.writeTo(connection.getOutputStream());

      // Make sure browser doesn't cache this URL.
      connection.setUseCaches(false);
      connection.close();

--READ from HTTP Posted--
      String protocol = currentPage.getProtocol();
      String host = hostField.getTextField().getText();
      String portString = portField.getTextField().getText();
      int port;
      try {
        port = Integer.parseInt(portString);
      } catch(NumberFormatException nfe) {
        port = -1; // I.e., default port of 80
      }
      String uri = uriField.getTextField().getText();
      URL dataURL = new URL(protocol, host, port, uri);
      URLConnection connection = dataURL.openConnection();

      // Make sure browser doesn't cache this URL.
      connection.setUseCaches(false);
      BufferedReader in =
        new BufferedReader(new InputStreamReader
                             (connection.getInputStream()));
      String line;
      String linefeed = "\n";
      resultsArea.setText("");
      while((line = in.readLine()) != null) {
        resultsArea.append(line);
        resultsArea.append(linefeed);
      }
    } catch(IOException ioe) {
      // Print debug info in Java Console
      System.out.println("IOException: " + ioe);
    }
    connection.close();
--regards,
Martin

----- Original Message -----
From: "Partha Ranjan Das" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, February 14, 2003 12:06 AM
Subject: Re: Pushing data to an Applet


> Yes, quite ok.
>
> -----Original Message-----
> From: Martin [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 20, 2002 8:12 PM
> To: A mailing list about Java Server Pages specification and reference
> Cc: [EMAIL PROTECTED]
> Subject: Re: Re: Pushing data to an Applet
>
>
> Partha-
>
> How about using the HTTP POST exchange?
>
> 1st applet gets the HTTPConnection from URL
> opens a PrintWriter (from the HTTPConnection OutputStream)
> writes to it
> closes
> -------------------------------------------------
> Receiving applet opens HTTPConnection (from the receiving URL)
> opens a InputStream
> Readline on InputStream until no more
> closes
> ---
> -M
>
> ----- Original Message -----
> From: "Partha Ranjan Das" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, February 13, 2003 9:34 AM
> Subject: Re: Pushing data to an Applet
>
>
> > Hi,
> > I think it is not possible without polling, because if the users are
> behind
> > proxy servers, then even if the server gets the remote addresses by
means
> of
> > getRemoteAddr() or some other method, this address will only be that of
> the
> > proxy server and not the actual m/cs themselves. I think to tunnel it
> thro'
> > firewall the best thing to do with a polling scheme is to connect to the
> > servlet using a URLConnection object and read/write using a
> > ServletOutputStream.
> > Not sure.. but looks feasible.
> > Regards,
> > Partha
> >
> > -----Original Message-----
> > From: Bhushan Bhangale [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, February 13, 2003 8:18 AM
> > To: [EMAIL PROTECTED]
> > Subject: Pushing data to an Applet
> >
> >
> > Hi,
> >
> > I have a Java Swing applet in my site. It talks to server via Applet to
> > Servlet Communication. There is one application running at the server
> side,
> > which processes some order.
> >
> > Now the functionality which I have to build is that the application
should
> > be able to push orders to the applets, so that the users who are
currently
> > watching the applet should be able to see the latest data automatically
> > without sendinga request.
> >
> > I searched on web but couldn't find anything as to how can I push data
to
> > all the connected applets of the site.
> >
> > The solution which I thought is the applet will poll the server after
> every
> > say 1 minute to check if there is any new to show. But suppose the
number
> of
> > user is more and there is nothing new to show, the applets will
> unnecessary
> > making the request to the server.
> >
> > I can't use Socket connection or RMI as the site will browsed outside
the
> > firewall. Is there any way by which I can push data from server to
> applets,
> > so that when ever new thing will come server will make connection with
> > applets and push data thereby using network only when needed. Unlike in
> > polling the network is used unnecessarily.
> >
> > Regards
> > Bhushan
> >
> >
> > *********************************************************************
> > Disclaimer: The information in this e-mail and any attachments is
> > confidential / privileged. It is intended solely for the addressee or
> > addressees. If you are not the addressee indicated in this message, you
> may
> > not copy or deliver this message to anyone. In such case, you should
> destroy
> > this message and kindly notify the sender by reply email. Please advise
> > immediately if you or your employer does not consent to Internet email
for
> > messages of this kind.
> > *********************************************************************
> >
> >
>
===========================================================================
> > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> > For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> DIGEST".
> >
> > Some relevant archives, FAQs and Forums on JSPs can be found at:
> >
> >  http://java.sun.com/products/jsp
> >  http://archives.java.sun.com/jsp-interest.html
> >  http://forums.java.sun.com
> >  http://www.jspinsider.com
> >
> *********************************************************************
> Disclaimer: The information in this e-mail and any attachments is
> confidential / privileged. It is intended solely for the addressee or
> addressees. If you are not the addressee indicated in this message, you
may
> not copy or deliver this message to anyone. In such case, you should
destroy
> this message and kindly notify the sender by reply email. Please advise
> immediately if you or your employer does not consent to Internet email for
> messages of this kind.
> *********************************************************************
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
>
> Some relevant archives, FAQs and Forums on JSPs can be found at:
>
>  http://java.sun.com/products/jsp
>  http://archives.java.sun.com/jsp-interest.html
>  http://forums.java.sun.com
>  http://www.jspinsider.com
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

 http://java.sun.com/products/jsp
 http://archives.java.sun.com/jsp-interest.html
 http://forums.java.sun.com
 http://www.jspinsider.com

Reply via email to