Why You Should
Not Override service
You can add support for other types of
requests by adding doPut, doTrace, etc.
You can add support for modification dates
Add a getLastModified method
The service method gives you automatic
support for:
HEAD, OPTIONS, and TRACE requests
Alternative: have doPost call doGet
public void doPost(HttpServletRequest request,
HttpServletResponse response) {
doGet(request, response);
}
19
Servlets
www.corewebprogramming.com
Initializing Servlets
Common in real life servlets
E.g., initializing database connection pools.
Use ServletConfig.getInitParameter to read
initialization parameters
Call getServletConfig to obtain the ServletConfig object
Set init parameters in web.xml (ver 2.2/2.3)
/WEB INF/web.xml
Many servers have custom interfaces to create web.xml
It is common to use init even when
you don't read init parameters
E.g., to set up data structures that don't change during the
life of the servlet, to load information from disk, etc.
20
Servlets
www.corewebprogramming.com
10