On Wed, 5 Dec 2001, Nikola Milutinovic wrote:
> Date: Wed, 5 Dec 2001 07:19:28 +0100
> From: Nikola Milutinovic <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: Tomcat Users List <[EMAIL PROTECTED]>
> Subject: Re: HTTP method POST is not supported by this URL
>
> > YourServlet extends javax.servlet.http.HttpServlet, and
> > javax.servlet.http.HttpServlet extends javax.servlet.GenericServlet,
> > the following is from HttpServlet in jakarta-servletapi-4-src.zip in
> > www.Apache.org:
> >
> > ...
> > protected void doPost(HttpServletRequest req, HttpServletResponse resp)
> > throws ServletException, IOException
> > {
> > String protocol = req.getProtocol();
> > String msg = lStrings.getString("http.method_post_not_supported");
> > if (protocol.endsWith("1.1")) {
> > resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
> > } else {
> > resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
> > }
> > }
> > ...
> >
> > it doesn't response anything to the client, so you need to override it
> > in YourServlet.
>
> You are right, but this is interesting, I have overriden the
> "service()" method, which in the HttpServlet dispatches a request to
> an appropriate method. Was it wrong to do that? Should I have left
> "service()" as it was and overriden "doGet()" and "doPost()" instead?
>
Yes. When you override service(), you override *all* of the automatic
stuff that HttpServlet does for you, such as processing HEAD requests
correctly -- as well as support for the lastModified() method.
> In my servlet I didn't particulary care which HTTP method was used to
> call the servlet, I just wanted the parameters of the request and I
> wanted to process them. I realize now that a more strict servlet
> should pay attention to the HTTP method used to call it. So, any
> comment?
>
Standard practice is to override only the doXxx() methods that you *do*
want to implement. One of the things that HttpServlet's service() method
does for you is take care of returning "not supported" errors for all the
methods that you chose not to support.
> Nix.
>
Craig
--
To unsubscribe: <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>