Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
17.6 An Applet That Sends POST Data
455
Listing 17.7 SendPost.java (continued)
                       "from a real Web server via HTTP,\n" +
                       "not from the local disk using\n" +
                       "a 'file:' URL. It is fine,\n" +
                       "however, if the Web server is\n" +
                       "running on your local system.";
      setEnabled(false);
    }
    hostField.getTextField().setText(host);
    inputPanel.add(hostField);
    portField =
      new LabeledTextField("Port ( 1 means default):", 4);
    String portString = String.valueOf(currentPage.getPort());
    portField.getTextField().setText(portString);
    inputPanel.add(portField);
    uriField =
      new LabeledTextField("URI:", 40);
    String defaultURI = "/servlet/coreservlets.ShowParameters";
    uriField.getTextField().setText(defaultURI);
    inputPanel.add(uriField);
    Canvas separator2 = new Canvas();
    inputPanel.add(separator2);
    sendButton = new Button("Submit Data");
    sendButton.addActionListener(this);
    Panel buttonPanel = new Panel();
    buttonPanel.add(sendButton);
    inputPanel.add(buttonPanel);
    add(inputPanel, BorderLayout.NORTH);
    resultsArea = new TextArea();
    resultsArea.setFont(new Font("Monospaced", Font.PLAIN, 14));
    resultsArea.setText(resultsMessage);
    add(resultsArea, BorderLayout.CENTER);
  }
  public void actionPerformed(ActionEvent event) {
    try {
      String protocol = currentPage.getProtocol();
      String host = hostField.getTextField().getText();
      String portString = portField.getTextField().getText();
      int port;
      try {
        port = Integer.parseInt(portString);
      } catch(NumberFormatException nfe) {
        port =  1; // I.e., default port of 80
      }
      String uri = uriField.getTextField().getText();
      URL dataURL = new URL(protocol, host, port, uri);
      URLConnection connection = dataURL.openConnection();
      
      // Make sure browser doesn't cache this URL.
      connection.setUseCaches(false);
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