public abstract class HttpServlet extends GenericServlet implements java.io.Serializable
doGet or doPost.
getLastModified. As long as the page hasn't changed,
it can avoid the overhead of any heavy processing or database queries.
You cannot use getLastModified if the response depends
on sessions, cookies, or any headers in the servlet request.
package test;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Hello extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Hello, World");
out.close();
}
}
| Constructor and Description |
|---|
HttpServlet() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doDelete(HttpServletRequest req,
HttpServletResponse res)
Process a DELETE request
|
protected void |
doGet(HttpServletRequest req,
HttpServletResponse res)
Process a GET or HEAD request
|
protected void |
doHead(HttpServletRequest req,
HttpServletResponse res)
Process a HEAD request.
|
protected void |
doOptions(HttpServletRequest req,
HttpServletResponse res)
Process an OPTIONS request
|
protected void |
doPost(HttpServletRequest req,
HttpServletResponse res)
Process a POST request
|
protected void |
doPut(HttpServletRequest req,
HttpServletResponse res)
Process a PUT request
|
protected void |
doTrace(HttpServletRequest req,
HttpServletResponse res)
Process a TRACE request
|
protected long |
getLastModified(HttpServletRequest req)
Returns the last-modified time for the page for caching.
|
protected void |
service(HttpServletRequest req,
HttpServletResponse res)
Services a HTTP request.
|
void |
service(ServletRequest request,
ServletResponse response)
Service a request.
|
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log, toStringpublic void service(ServletRequest request, ServletResponse response) throws ServletException, java.io.IOException
service in interface Servletrequest - request information. Normally servlets will cast this
to HttpServletRequestresponse - response information. Normally servlets will cast this
to HttpServletRequestServletExceptionjava.io.IOExceptionprotected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
req - request informationres - response object for returning data to the client.ServletExceptionjava.io.IOExceptionprotected long getLastModified(HttpServletRequest req)
getLastModified
to improve performance. Servlet engines like Resin can
cache the results of the page, resulting in near-static performance.req - the requestprotected void doHead(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
req - the client requestres - response to the clientServletExceptionjava.io.IOExceptionprotected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
req - the client requestres - response to the clientServletExceptionjava.io.IOExceptionprotected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
req - the client requestres - response to the clientServletExceptionjava.io.IOExceptionprotected void doPut(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
req - the client requestres - response to the clientServletExceptionjava.io.IOExceptionprotected void doDelete(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
req - the client requestres - response to the clientServletExceptionjava.io.IOExceptionprotected void doOptions(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
req - the client requestres - response to the clientServletExceptionjava.io.IOExceptionprotected void doTrace(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
req - the client requestres - response to the clientServletExceptionjava.io.IOException