21.6. An Applet That Sends POST Data

Listing 21.8 presents an applet that follows the approach outlined in the previous section. The applet uses a URLConnection and an attached ByteArrayOutputStream to send POST data to a URL the user specifies. The applet also makes use of the LabeledTextField class, available fordownload from http://www.corewebprogramming.com/.

Figure 21-4 shows the results of submitting the data to the ShowParameters servlet, a small servlet that builds a Web page illustrating all of the query parameters sent to it; see Section 19.6 (The Client Request: Form Data).

Figure 21-4. Result of using SendPost to send POST data to the ShowParameters servlet.
Listing 21.8. SendPost.java
 import java.applet.Applet; import java.awt.*; ...

Get Core Web Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.