|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.servlet.GenericServlet | +--javax.servlet.http.HttpServlet
HttpServlet is a convenient abstract class for creating servlets.
Normally, servlet writers will only need to override
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 Summary | |
HttpServlet()
|
Method Summary | |
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 |
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. |
Methods inherited from class javax.servlet.GenericServlet |
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public HttpServlet()
Method Detail |
public void service(ServletRequest request, ServletResponse response) throws ServletException, java.io.IOException
javax.servlet.Servlet
req
- request information. Normally servlets will cast this
to HttpServletRequest
res
- response information. Normally servlets will cast this
to HttpServletRequest
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
req
- request informationres
- response object for returning data to the client.protected 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 doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
req
- the client requestres
- response to the clientprotected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
req
- the client requestres
- response to the clientprotected void doPut(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
req
- the client requestres
- response to the clientprotected void doDelete(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
req
- the client requestres
- response to the clientprotected void doOptions(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
req
- the client requestres
- response to the clientprotected void doTrace(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException
req
- the client requestres
- response to the client
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |