java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.bzdev.net.servlets.EncapsulatingServlet
- All Implemented Interfaces:
Serializable
,Servlet
,ServletConfig
Servlet implemented by encapsulating an instance of
ServletAdapter
.
Subclasses are expected to provide a constructor with no arguments
that creates an instance of ServletAdapter
and passes it to
the constructor of this class. For example,
public class OurServlet extends EncapsulatingServlet { public OurServlet() { super(new OurAdapter()); } }
To use this class, A JAR file containing the servlet API must be on the classpath or accessible via the module path. For releases whose manifest does not contain an AUTOMATIC-MODULE-NAME declaration, the file name must be servlet-api.jar. This of course is subject to change.
ServletAdapter states are handled internally by setting and getting
a session attribute named "state", so the attribute name "state" should
be treated a reserved name. Servlet adapters use a subset of the
servlet API. If more of the API is needed (e.g., for logins),
methods such as
doPost(HttpServletRequest,HttpServletResponse)
should be overridden to add additional functionality.
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
EncapsulatingServlet
(ServletAdapter adapter) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
destroy()
Destroy a servlet.protected void
doDelete
(HttpServletRequest req, HttpServletResponse res) Called by the server (via a service method) to allow a servlet to handle a DELETE request.protected void
doGet
(HttpServletRequest req, HttpServletResponse res) Called by the server (via a service method) to allow a servlet to handle a GET request.protected void
doPost
(HttpServletRequest req, HttpServletResponse res) Called by the server (via a service method) to allow a servlet to handle a POST request.protected void
doPut
(HttpServletRequest req, HttpServletResponse res) Called by the server (via a service method) to allow a servlet to handle a PUT request.void
init()
Initialize a servlet's adapter.Methods inherited from class javax.servlet.http.HttpServlet
doHead, doOptions, doTrace, getLastModified, service, service
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Constructor Details
-
EncapsulatingServlet
Constructor.- Parameters:
adapter
- the servlet adapter to encapsulate.
-
-
Method Details
-
doGet
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException Called by the server (via a service method) to allow a servlet to handle a GET request. Please see the HttpServlet method doGet for a full description.- Overrides:
doGet
in classHttpServlet
- Parameters:
req
- anHttpServletRequest
object that contains the request the client has made to the servlet.res
- anHttpServletResponse
object that contains the response the client has made to the servlet.- Throws:
IOException
- an IO error occurred during processingServletException
- if the request for the GET could not be handled.
-
doPost
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException Called by the server (via a service method) to allow a servlet to handle a POST request. Please see the HttpServlet method doPost for a full description.- Overrides:
doPost
in classHttpServlet
- Parameters:
req
- anHttpServletRequest
object that contains the request the client has made to the servlet.res
- anHttpServletResponse
object that contains the response the client has made to the servlet.- Throws:
IOException
- an IO error occurred during processingServletException
- if the request for the POST could not be handled.
-
doPut
protected void doPut(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException Called by the server (via a service method) to allow a servlet to handle a PUT request. Please see the HttpServlet method doPut for a full description.- Overrides:
doPut
in classHttpServlet
- Parameters:
req
- anHttpServletRequest
object that contains the request the client has made to the servlet.res
- anHttpServletResponse
object that contains the response the client has made to the servlet.- Throws:
IOException
- an IO error occurred during processingServletException
- if the request for the PUT could not be handled.
-
doDelete
protected void doDelete(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException Called by the server (via a service method) to allow a servlet to handle a DELETE request. Please see the HttpServlet method doDelete for a full description. for a full description.- Overrides:
doDelete
in classHttpServlet
- Parameters:
req
- anHttpServletRequest
object that contains the request the client has made to the servlet.res
- anHttpServletResponse
object that contains the response the client has made to the servlet.- Throws:
IOException
- an IO error occurred during processingServletException
- if the request for the PUT could not be handled.
-
init
Initialize a servlet's adapter. Please see the GenericServlet method init() for the official description. The servlet method init(ServletConfig) will typically be called to initialize the servlet. That method stores the servlet configuration object and then calls this method - init() - to perform the initialization.- Overrides:
init
in classGenericServlet
- Throws:
ServletException
- if the initialization fails.
-
destroy
public final void destroy()Destroy a servlet. Please seeGenericServlet.destroy()
for a full description.- Specified by:
destroy
in interfaceServlet
- Overrides:
destroy
in classGenericServlet
-