Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
16.12 A Debugging Web Server
425
Listing 16.9 EchoServer.java (continued)
  public void handleConnection(Socket server)
      throws IOException{
    System.out.println
        (serverName + ": got connection from " +
         server.getInetAddress().getHostName());
    BufferedReader in = SocketUtil.getReader(server);
    PrintWriter out = SocketUtil.getWriter(server);
    String[] inputLines = new String[maxRequestLines];
    int i;
    for (i=0; i
      inputLines[i] = in.readLine();
      if (inputLines[i] == null) // Client closed connection
        break;
      if (inputLines[i].length() == 0) { // Blank line
        if (usingPost(inputLines)) {
          readPostData(inputLines, i, in);
          i = i + 2;
        }
        break;
      }
    }
    printHeader(out);
    for (int j=0; j
      out.println(inputLines[j]);
    }
    printTrailer(out);
    server.close();
  }
  // Send standard HTTP response and top of a standard Web page.
  // Use HTTP 1.0 for compatibility with all clients.
  
  private void printHeader(PrintWriter out) {
    out.println
      ("HTTP/1.0 200 OK\r\n" +
       "Server: " + serverName + "\r\n" +
       "Content Type: text/html\r\n" +
       "\r\n" +
       "
         "\" //W3C//DTD HTML 4.0 Transitional//EN\">\n" +
       "\n" +
       "\n" +
       "  " + serverName + " Results\n" +
       "\n" +
       "\n" +
       "\n" +
       "

" + serverName +

         " Results\n" +
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