JavaScript is disabled on your browser.
javax.servlet.http

Class HttpServlet

  • All Implemented Interfaces:
    java.io.Serializable, Servlet, ServletConfig


    public abstract class HttpServlet
    extends GenericServlet
    implements java.io.Serializable
    The mother-of-all-HttpServlets. Every normal http servlet extends this class and overrides either the doGet or doPost methods (or both). The server calls service. Service in its turn calls doGet, doPost, whatever, depending on the client's request.
    Since:
    1.0
    See Also:
    Serialized Form
    • Constructor Detail

      • HttpServlet

        public HttpServlet()
        Does nothing
    • Method Detail

      • doGet

        protected void doGet(HttpServletRequest request,
         HttpServletResponse response)
         throws ServletException,
         java.io.IOException
        This method is called on a "GET" request. The default implementation is that for HTTP/1.0 requests we return a HttpServletResponse.SC_BAD_REQUEST status code, and for HTTP/1.1 requests, HttpServletResponse.SC_METHOD_NOT_ALLOWED.
        Throws:
        ServletException - if an Servlet Exception occurs
        java.io.IOException - if an IOException occurs
      • getLastModified

        protected long getLastModified(HttpServletRequest request)
        Returns the time the requested uri was last modified in seconds since 1 january 1970. Default implementation returns -1.
      • doHead

        protected void doHead(HttpServletRequest request,
         HttpServletResponse response)
         throws ServletException,
         java.io.IOException
        This method is called on a "HEAD" request. This method calls the doGet method with the request parameter, but the response object is replaced by a HttpServletResponse that is identical to the reponse, but it has a "dummy" OutputStream.
        The doGet method should perform a check like the following:
        if(request.getMethod().equals("HEAD")) { ... }
        if it wants to know whether it was called from doHead.
        Throws:
        ServletException - if an Servlet Exception occurs
        java.io.IOException - if an IOException occurs
        Since:
        2.0
      • doPost

        protected void doPost(HttpServletRequest request,
         HttpServletResponse response)
         throws ServletException,
         java.io.IOException
        This method is called on a "POST" request. The default implementation is that for HTTP/1.0 requests we return a HttpServletResponse.SC_BAD_REQUEST status code, and for HTTP/1.1 requests, HttpServletResponse.SC_METHOD_NOT_ALLOWED.
        Throws:
        ServletException - if an Servlet Exception occurs
        java.io.IOException - if an IOException occurs
      • doPut

        protected void doPut(HttpServletRequest request,
         HttpServletResponse response)
         throws ServletException,
         java.io.IOException
        This method is called on a "PUT" request. The default implementation is that for HTTP/1.0 requests we return a HttpServletResponse.SC_BAD_REQUEST status code, and for HTTP/1.1 requests, HttpServletResponse.SC_METHOD_NOT_ALLOWED.
        Throws:
        ServletException - if an Servlet Exception occurs
        java.io.IOException - if an IOException occurs
        Since:
        2.0
      • doDelete

        protected void doDelete(HttpServletRequest request,
         HttpServletResponse response)
         throws ServletException,
         java.io.IOException
        This method is called on a "DELETE" request. The default implementation is that for HTTP/1.0 requests we return a HttpServletResponse.SC_BAD_REQUEST status code, and for HTTP/1.1 requests, HttpServletResponse.SC_METHOD_NOT_ALLOWED.
        Throws:
        ServletException - if an Servlet Exception occurs
        java.io.IOException - if an IOException occurs
        Since:
        2.0
      • doOptions

        protected void doOptions(HttpServletRequest request,
         HttpServletResponse response)
         throws ServletException,
         java.io.IOException
        This method is called on a "OPTIONS" request. It tells the client which methods are supported by the servlet. This comes down to an implementation where TRACE and OPTIONS are supported by default. GET, HEAD, POST, DELETE and PUT are added to this list if the subclass has its own implementation of the doGet, doHead, doPost, doDelete or doPut method respectively.
        Throws:
        ServletException - if an Servlet Exception occurs
        java.io.IOException - if an IOException occurs
        Since:
        2.0
      • doTrace

        protected void doTrace(HttpServletRequest request,
         HttpServletResponse response)
         throws ServletException,
         java.io.IOException
        This method is called on a "TRACE" request. This method is for debugging purposes.
        When a client makes a TRACE request the following is returned:
        content type = "message/http"
        message size: <size of the complete message>
        first line of the message : TRACE <requested uri> <protocol>
        on the following lines all the request header names and values
        Throws:
        ServletException - if an Servlet Exception occurs
        java.io.IOException - if an IOException occurs
        Since:
        2.0
      • service

        protected void service(HttpServletRequest request,
         HttpServletResponse response)
         throws ServletException,
         java.io.IOException
        This method looks whether the request is a POST, GET, etc method, and then calls the appropriate doPost, doGet, whatever method.
        If the request method is something it can't handle it sends a HttpServletResponse.SC_BAD_REQUEST error through the response.
        Throws:
        ServletException - an error has occured
        java.io.IOException - an error has occured
      • service

        public void service(ServletRequest request,
         ServletResponse response)
         throws ServletException,
         java.io.IOException
        Frontend for calling service(HttpServletRequest,HttpServletResponse).

        This method tries to typecast the ServletRequest and the ServletResponse to HttpServletRequest and HttpServletResponse and then call service(HttpServletRequest,HttpServletResponse).

        Specified by:
        service in interface Servlet
        Specified by:
        service in class GenericServlet
        Parameters:
        request - The client's request
        response - The class to write the response date to.
        Throws:
        ServletException - an error has occured
        java.io.IOException - an error has occured
        See Also:
        SingleThreadModel

AltStyle によって変換されたページ (->オリジナル) /