Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
17.6 An Applet That Sends POST Data
453
10. Send the real data. 
byteStream.writeTo(connection.getOutputStream());
11. Open an input stream. You typically use a 
BufferedReader
for ASCII or binary data and an 
ObjectInputStream
 for serial 
ized Java objects.
BufferedReader in =
new BufferedReader(new InputStreamReader
(connection.getInputStream()));
12. Read the result. 
The specific details will depend on what type of data the server 
sends. Here is an example that does something with each line 
sent by the server:
String line;
while((line = in.readLine()) != null) {
doSomethingWith(line);
}
13. Pat yourself on the back. Yes, the procedure for handling 
POST
 is long and tedious. Fortunately, it is a relatively rote pro 
cess. Besides, you can always download an example from 
www.coreservlets.com
 and use it as a starting point.
The next section gives an example of an applet that performs these steps.
17.6 An Applet That Sends POST 
Data
Listing 17.7 presents an applet that follows the approach outlined in the pre 
vious section. The applet uses a 
URLConnection
 and an attached 
Byte 
ArrayOutputStream
 to send 
POST
 data to a URL the user specifies. The
applet also makes use of the 
LabeledTextField
 class, shown previously in
Listing 2.2 and available for download from 
http://www.coreserv 
lets.com/
. 
Figures 17 4 and 17 5 show the results of submitting the data to the
ShowParameters
 servlet and 
EchoServer
 HTTP server, respectively. 
Home page for this book: www.coreservlets.com; Home page for sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

jsp web hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved