Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
454
Chapter 17 Using Applets As Servlet Front Ends
Listing 17.7 SendPost.java 
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
/** Applet that reads firstName, lastName, and
 *  emailAddress parameters and sends them via
 *  POST to the host, port, and URI specified.
 */
public class SendPost extends Applet
                      implements ActionListener {
  private LabeledTextField firstNameField, lastNameField,
                           emailAddressField, hostField,
                           portField, uriField;
  private Button sendButton;
  private TextArea resultsArea;
  URL currentPage;
  
  public void init() {
    setBackground(Color.white);
    setLayout(new BorderLayout());
    Panel inputPanel = new Panel();
    inputPanel.setLayout(new GridLayout(9, 1));
    inputPanel.setFont(new Font("Serif", Font.BOLD, 14));
    firstNameField =
      new LabeledTextField("First Name:", 15);
    inputPanel.add(firstNameField);
    lastNameField =
      new LabeledTextField("Last Name:", 15);
    inputPanel.add(lastNameField);
    emailAddressField =
      new LabeledTextField("Email Address:", 25);
    inputPanel.add(emailAddressField);
    Canvas separator1 = new Canvas();
    inputPanel.add(separator1);
    hostField =
      new LabeledTextField("Host:", 15);
    
    // Applets loaded over the network can only connect
    // to the server from which they were loaded.
    hostField.getTextField().setEditable(false);
    
    currentPage = getCodeBase();
    // getHost returns empty string for applets from local disk.
    String host = currentPage.getHost();
    String resultsMessage = "Results will be shown here...";
    if (host.length() == 0) {
      resultsMessage = "Error: you must load this applet\n" +
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