aspose file tools*
The moose likes Servlets and the fly likes Error 405 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Error 405" Watch "Error 405" New topic
Author

Error 405

Hazel Sisson
Greenhorn

Joined: Feb 12, 2002
Posts: 17
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

Joined: Feb 20, 2001
Posts: 3695

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

Joined: Feb 12, 2002
Posts: 17
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

Joined: Nov 06, 2000
Posts: 1506
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
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error 405
 
Similar Threads
Sequence of request parameters
HTTP Status 405 error comes
servlet programming problem in Eclipse
How to call servlet which is inside the jar??
refresh in post method