Main Content

Web page (http) error status 405

Archive - Originally posted on "The Horse's Mouth" - 2008-01-12 01:06:18 - Graham Ellis

Running his first Java Servlet today, one of my delegates reported an HTTP status 405 from his code when he tried to browse to it. A new one on me ... I am used to a good number of other return codes, but hadn't seen this before.

It turns out that the cause was the lack of an appropriate doGet method in the Servlet class; in my delegate's case he had provided a doGet but with the wrong type of parameters, so instead of providing a method that Tomcat could call up he had provided what was, in effect, an internally available method only. I was able to reproduce the error later for the purpose of this note by simply mis-spelling doGet as doget ... Capital G to lower case g.

Wrong:

public void doget ( HttpServletRequest request,
   HttpServletResponse response )
   throws ServletException, IOException {


Right:

public void doGet ( HttpServletRequest request,
   HttpServletResponse response )
   throws ServletException, IOException {




Here are some other common 400 series errors we come across, and their typical causes to help you troubleshoot:

400 - Bad request

Typically this is caused by a user writing his own web client (for example using Web 2 techniques) and so making an illegal instruction call to the server

403 - Forbidden

A file exists on the server that is mapped to the URL that was given, but that file is not readable by the web server process. Typically, this error occurs when the web site administrator is uploading a file via FTP or copying it into place and gets the file permissions or ownership wrong.

404 - Not Found

The most common of the lot. The request was valid, but doesn't point to anything which exists on the server. It could be that the user (at the browser) has mistyped a URL, it could be that there's a broken link on a web page pointing at thin air, and it could be that a file that should exist on the server doesn't, or has been accidentally deleted. You will also get a lot of 404 errors in your server logs relating to malicious software that's poking around looking for holes in your security!

401 - Unauthorized

The page exists, but the user has failed to enter a correct user name and passwordd to access it. See .htpasswd in the Apache documentation.