Forward Requests

When developing a WWW site, it often is desirable to combine the features of several different servers. Jetty can forward requests that it receives to another WWW server and pass the response it back as the response to the original request.

While similar to a redirect, forwarding offers several key benefits:

  • The response is passed back through Jetty, so it may be filtered or modified in other ways.
  • The browser only sees a single request and response and two round trips are not required.
  • The client does not need to access the destination server, so it may be placed behind a firewall on a secure network. Jetty thus can act as a smart proxy.
For this demonstration, a forward handler has been configured to forward all request to paths beginning with "/Forward" to the localhost, i.e. Jetty is forwarding the request to itself. All of the following URLs access this page:
/Jetty/Demo/forward.html - No forwards.
/Forward/Jetty/Demo/forward.html - A single forward.
/Forward/Forward/Forward/Jetty/Demo/forward.html - Three forwards.