Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
424
Chapter 16 Using HTML Forms
Listing 16.9 EchoServer.java 
import java.net.*;
import java.io.*;
import java.util.StringTokenizer;
/** A simple HTTP server that generates a Web page
 *  showing all the data that it received from
 *  the Web client (usually a browser). To use this,
 *  start it on the system of your choice, supplying
 *  a port number if you want something other than
 *  port 8088. Call this system server.com. Next,
 *  start a Web browser on the same or a different
 *  system, and connect to http://server.com:8088/whatever.
 *  The resultant Web page will show the data that your browser
 *  sent. For debugging in servlet or CGI programming, 
 *  specify http://server.com:8088/whatever as the
 *  ACTION of your HTML form. You can send GET
 *  or POST data; either way, the resultant page
 *  will show what your browser sent.
 */
public class EchoServer extends NetworkServer {
  protected int maxRequestLines = 50;
  protected String serverName = "EchoServer";
  /** Supply a port number as a command line
   *  argument. Otherwise port 8088 will be used.
   */
  
  public static void main(String[] args) {
    int port = 8088;
    if (args.length > 0) {
      try {
        port = Integer.parseInt(args[0]);
      } catch(NumberFormatException nfe) {}
    }
    new EchoServer(port, 0);
  }
  public EchoServer(int port, int maxConnections) {
    super(port, maxConnections);
    listen();
  }
  /** Overrides the NetworkServer handleConnection
   *  method to read each line of data received, save it
   *  into an array of strings, then send it
   *  back embedded inside a PRE element in an
   *  HTML page.
   */
  
Second edition of this book: www.coreservlets.com; 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