| java.lang.Object javax.servlet.GenericServlet javax.servlet.http.HttpServlet
HttpServlet | abstract public class HttpServlet extends GenericServlet implements Serializable(Code) | | HttpServlet is a convenient abstract class for creating servlets.
Normally, servlet writers will only need to override
doGet or doPost .
Caching
HttpServlet makes caching simple. Just override
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.
Hello, world
The Hello.java belongs in myapp/WEB-INF/classes/test/Hello.java under the
application's root. Normally, it will be called as
http://myhost.com/myapp/servlet/test.Hello. If the server doesn't use
applications, then use /servlet/test.Hello.
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();
}
}
|
Method Summary | |
protected void | doDelete(HttpServletRequest req, HttpServletResponse res) | protected void | doGet(HttpServletRequest req, HttpServletResponse res) | protected void | doHead(HttpServletRequest req, HttpServletResponse res) Process a HEAD request. | protected void | doOptions(HttpServletRequest req, HttpServletResponse res) | protected void | doPost(HttpServletRequest req, HttpServletResponse res) | protected void | doPut(HttpServletRequest req, HttpServletResponse res) | protected void | doTrace(HttpServletRequest req, HttpServletResponse res) | protected long | getLastModified(HttpServletRequest req) Returns the last-modified time for the page for caching.
If at all possible, pages should override getLastModified
to improve performance. | public void | service(ServletRequest request, ServletResponse response) Service a request. | protected void | service(HttpServletRequest req, HttpServletResponse res) Services a HTTP request. |
getLastModified | protected long getLastModified(HttpServletRequest req)(Code) | | Returns the last-modified time for the page for caching.
If at all possible, pages should override getLastModified
to improve performance. Servlet engines like Resin can
cache the results of the page, resulting in near-static performance.
Parameters: req - the request the last-modified time of the page. |
service | protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException(Code) | | Services a HTTP request. Automatically dispatches based on the
request method and handles "If-Modified-Since" headers. Normally
not overridden.
Parameters: req - request information Parameters: res - response object for returning data to the client. |
|
|