Karun Kathuria wrote:

> I've made an application using applet-servlet combination.
>
> The applet sends some parameters to the servlet (using GET method) and the
> servlet responds with an html page.
>
> I've used MyApplet.showDocument(...) so that the html page sent by the
> servlet gets back to the browser and not to the applet.
>
> Now I would like to achieve the same thing using POST method.
> Is there any way out?

The difference between GET and POST lies in the fact that POST is carries out
its operation in two passes.

1) write parameters to the server, and then
2) read response from the server.

<example>

      URLConnection urlConn = url.openConnection();
      urlConn.setDoInput(true);
      urlConn.setDoOutput(true);
      urlConn.setUseCaches(false);

urlConn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");

      postData.append("userid=");
      postData.append(URLEncoder.encode("gandhi));

      postData.append("&");
      postData.append("password=");
      postData.append(URLEncoder.encode("secret"));


///////////////////////////////////////////////////////////////////////////////////

      // send request
//

///////////////////////////////////////////////////////////////////////////////////

      streamOut = new DataOutputStream(urlConn.getOutputStream());
      streamOut.writeBytes(postData.toString());
      streamOut.flush();
      streamOut.close();
      streamOut = null;


///////////////////////////////////////////////////////////////////////////////////

      // Read now
//

///////////////////////////////////////////////////////////////////////////////////

      streamIn = new DataInputStream(urlConn.getInputStream());
      int inputValue;
      while ((inputValue=streamIn.read()) > -1)
           nowCount += inputValue;
      streamIn.close();

</example>

==--==--==--==--==--==--==--==--==--==--==--==--==--==
S.Ramaswamy
Matrix Infotech Syndicate
D-7, Poorti, Vikaspuri, New Delhi, 110018, India
PHONE:    +91-11-5610050,   FAX: +91-11-5535103
WEB         http://MatrixInfotech.HyperMart.Net
==--==--==--==--==--==--==--==--==--==--==--==--==--==

___________________________________________________________________________
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