Hi, I have a problem with a servlet program that takes input from an HTML form and analyzes it. When I try to run the servlet on my browser, I get the following error message: Apache Tomcat/4.0.1 - HTTP Status 405 - HTTP method GET is not supported by this URL. I'm not sure which method it's talking about - there are methods like getParameter() and getServletContext().getRealPath(), but no others. The doGet() method has not been overwritten. I'm running JDK1.3. Do you have any ideas what it could be? Thanks very much.
That would be your problem. If you don't provide an implementation for doGet() in your servlet that extends HttpServlet, then the browser will show 405, meaning that your servlet doesn't support the method you've just tried. In your case, an HTTP GET.
posted 17 years ago
Wierd... It seems to have a doPost method instead of doGet. (The servlet is taken from a Sun tutorial, so it should work!) Is it compulsory to have a doGet method in every servlet? Thanks for your help.
No, it's not compulsory to have a doGet method in every servlet. It all depends on how your servlet may be accessed. It usually a safe bet to have both of them though, by having one call the other. The error you are getting seems like the servlet was accessed using a GET method and your servlet only implemented POST.
Bosun (SCJP, SCWCD).
So much trouble in the world -- Bob Marley
This is an HTTP GET request. In order to do a POST request (which the sun servlet you got from the tutorial MUST be called from, because it only has a doPost() method implemented).. you have to build an HTML form, and the form's action attribute (for this example) should be 'MyServlet' and the method should be 'POST' [ February 12, 2002: Message edited by: Mike Curwen ]