| javax.servlet.http.HttpServlet org.gomba.DispatcherServlet
DispatcherServlet | final public class DispatcherServlet extends HttpServlet (Code) | | This Servlet forwards HTTP requests to other servlets. Target servlets are
mapped to HTTP request methods: GET, POST, PUT, DELETE. This servlet is
useful to build read/write/update/delete web services by compositing servlets
that manage only a single operation.
Init params:
- GET
- The name of the servlet to handle GET requests. This method is normally
used for read (SELECT in SQL) operations. (Optional)
- POST
- The name of the servlet to handle POST requests. This method is normally
used for creation (INSERT in SQL) operations. (Optional)
- PUT
- The name of the servlet to handle PUT requests. This method is normally
used for update (UPDATE in SQL) operations. (Optional)
- DELETE
- The name of the servlet to handle DELETE requests. This method is
obviously used for deletion (DELETE in SQL) operations. (Optional)
Design note. While this 'dispatcher' approach may seem to break the Servlet
contract by splitting the processing of HTTP methods among multiple servlets,
we designed this way with the explicit purpose of remaining inside the
Servlet API and not creating our own framework inside the Servlet framework.
The benefits of this design are:
- All configuration is done through standard mechanisms (web.xml).
- A web service can smoothly grow from a read-only service (which is
fairly easy to configure: 1 servlet, 1 servlet-mapping), to a more
sophisticated read/write/update/delete service (which involves the
configuration of 4 servlets and 1 servlet-mapping).
An alternative design would be having a single Servlet handling all HTTP
methods and invoking a "service" mapped to it. This would require:
- Creating our own "service" abstraction.
- Having our own XML configuration file besides the web.xml
Which we do not like at all.
author: Flavio Tordini version: $Id: DispatcherServlet.java,v 1.3 2004/09/16 09:23:16 flaviotordini Exp $ |
Methods inherited from javax.servlet.http.HttpServlet | protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc) protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc) protected void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc) protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc) protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc) protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc) protected void doTrace(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc) protected long getLastModified(HttpServletRequest req)(Code)(Java Doc) protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc) public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException(Code)(Java Doc)
|
|
|