- Forward


Design of an Improved HTTP Server
A Simple Network Application in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Comments on our Current Design
Back SMYC Forward
  • Handling GET Requests:
    • We can do very little in response to a GET request
    • Adding functionality will complicate the code
  • Handling Other Requests:
    • Adding support for POST requests will further complicate the code
Improving the Current Design
Back SMYC Forward
  • What's Needed?
    • A way to "instruct" the connection handler how to handle requests.
  • A Solution:
    • The Strategy Pattern
The Servlet Interface
Back SMYC Forward
javaexamples/http/v3/HttpServlet.java
 
An Improved HTTP Connection Handler
Back SMYC Forward
javaexamples/http/v3/HttpConnectionHandler.java
 
An Abstract Servlet
Back SMYC Forward
javaexamples/http/v3/AbstractHttpServlet.java
 
Invoking Servlets
Back SMYC Forward
  • A General Approach:
    • Map servlet to URLs
  • Different Kinds of Mappings
    • Map one servlet to one URL
    • Map one servlet to one directory
    • Map one servlet to files with a given extension
A Servlet Factory
Back SMYC Forward
javaexamples/http/v3/HttpServletFactory.java
 
A Default Servlet
Back SMYC Forward
javaexamples/http/v3/DefaultHttpServlet.java
 
An Example
Back SMYC Forward
  • The Motivation:
    • Many WWW sites use a single "template" for all of their pages
    • The easiest way to do this is to include all of the template information (e.g., headers, menu bars, footers) in each page
    • The problem with this approach is that you have the same information in multiple files which makes it difficult to change, etc...
  • Using a Servlet:
    • Have a servlet that writes the common information into each response
An Example (cont.)
Back SMYC Forward
javaexamples/http/v3/TemplatedHttpServlet.java
 
There's Always More to Learn
Back -