This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
Joined: Feb 12, 2002
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 ]