File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes HTTP Status 405 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTP Status 405" Watch "HTTP Status 405" New topic

HTTP Status 405

Sophia Choi
Ranch Hand

Joined: Mar 22, 2002
Posts: 106
I have run Upload File programs according to O'Reilly.They are successful in the office. But I meet problem at home.
The error message is as following.
The specified HTTP method is not allowed for the requested resource (HTTP method POST is not supported by this URL).
How can I solve it?
Thanks a lot.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12803
You get that message if the servlet your URL addresses does not have a doPost method to handle POST.
So the servlet engine can find something with that URL but it is probably not the one you want. Exactly what URL are you using, which servlet engine, what did you install that is supposed to be handling the URL?
Sophia Choi
Ranch Hand

Joined: Mar 22, 2002
Posts: 106
Actually, the servlet has only a doPost method. The engine is Tomcat 4.1.24.
It is same in my office. My problem is still having.
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{
PrintWriter out=res.getWriter();
String dir = ".";
out.println("Upload Test start...");
//MultipartRequest multi = new MultipartRequest(req,".",5*1024*1024);
MultipartRequest multi = new MultipartRequest(req,dir,5*1024*1024);
Enumeration params = multi.getParameterNames();
String name=(String)params.nextElement();
String value =multi.getParameter(name);
out.println(name + " = " + value);
Enumeration files=multi.getFileNames();
String name = (String)files.nextElement();
String filename = multi.getFilesystemName(name);
String type = multi.getContentType(name);
File f=multi.getFile(name);
out.println("name: "+name);
out.println("filename: "+filename);
out.println("type: "+ type);
if(f != null){
out.println("length: "+f.length());
catch(Exception e){
vijaykumar shah

Joined: Jul 02, 2003
Posts: 23
There are two ways by which this error can be solved ..
before that some questions
1. Are you calling this servlet from a form where u get the data through a html file .
2. what is the configuration of the IE at your place and at office.. are both IE version same
if after this also the error is not solved try using generic servlet and write the service method and try it .. may be it would solve the problem
also see that on tomcat r u getting any error message..
may be its problem with the tomcat settings also
also try putting try catch block in your code and use exception.printstacktrace...
this would help you to solve the problems
best luck
vijay shah
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12803
Sophia - read my post again. Then read the documentation for HttpServletResponse - SC_METHOD_NOT_ALLOWED = 405 response code.
You may think that you are correctly addressing the servlet with the doPost method, but that response code indicates that you are not getting through to it.
As Vijay suggests, look carefully at the form that is supposed to be sending a request to the servlet and the URL it is addressing.
Also, you might look at the Tomcat logs to see what Tomcat is seeing - you should be able to see every single request.
I agree. Here's the link:
subject: HTTP Status 405