• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error 405

 
Hazel Sisson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The doGet() method has not been overwritten

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.
 
Hazel Sisson
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Setting aside any considerations of servlet mappings...

If you type in :

http://localhost:8080/servlet/MyServlet

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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic