[Advanced-java] Sending a Post from an applet to a servlet

Lorin Davis ldavis at pangaeainc.com
Thu Apr 10 23:10:21 2003


Hi all 

I have an applet that opens a URLConnection and a servlet that receives this
connection in the doGet () 
I'm trying to change this to go through the doPost () with a parameter added
to the post.

Here's how I do my current communications

myapplet.java 
  URL XMLURL = new
URL("http://testserver/serlvets/myservlet?token=<?xml%20version="1.0"?><XML>
<CMD>getXML</CMD></XML>");          
  URLConnection connection = XMLURL.openConnection();
  InputStream is = connection.getInputStream() ;

  InputStreamReader isr = new InputStreamReader( is );
  BufferedReader br = new BufferedReader( isr );

  while ((bufferIn = br.readLine()) != null) {
    xml = xml + bufferIn;
  }

then on 
myservlet.java
there would be something like this
  public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
    String token = request.getParameter(xmlParam);
    // now do something with the xml that was passed in 
  }

The problem is that we want to compress our tokenXML (as sometimes it can be
very long) before sending it to the servlet and not send it as part of the
URL instead send it as a parameter of a post.  

My understanding is you can send any type of data to a post method as a
parameter but I cannot figure out how to do this from an applet yet any help
would be much appreciated.

In an HTLM you would use the <FORM> tags and <INPUT TYPE> tags to send data.

Thanks.