File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTP Status 405" Watch "HTTP Status 405" New topic
Author

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
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
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?
Bill


Java Resources at www.wbrogden.com
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.
Code:
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
String dir = ".";
try{
out.println("Upload Test start...");
//MultipartRequest multi = new MultipartRequest(req,".",5*1024*1024);
MultipartRequest multi = new MultipartRequest(req,dir,5*1024*1024);
out.println("123");
out.println("<html>");
out.println("<head><title>UploadTest</title></head>");
out.println("<body>");
out.println("<H1>UploadTest</h1>");
out.println("<h3>Params:</h3>");
out.println("<Pre>");
Enumeration params = multi.getParameterNames();
while(params.hasMoreElements()){
String name=(String)params.nextElement();
String value =multi.getParameter(name);
out.println(name + " = " + value);
}
out.println("</PRE>");
out.println("<h3>Files:</h3>");
out.println("<pre>");
Enumeration files=multi.getFileNames();
while(files.hasMoreElements()){
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());
out.println();
}
out.println("</pre>");
}
}
catch(Exception e){
out.println("<pre>");
e.printStackTrace(out);
out.println("<pre>");
}
out.println("</body></html>");
}
}
vijaykumar shah
Greenhorn

Joined: Jul 02, 2003
Posts: 23
Hello,
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
v.shah@portlog.com
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
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.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTTP Status 405
 
Similar Threads
regarding unsupported post method
restrict access to jsp from WSAD/Websphere
Why 2 service() methods in HttpServlet??
GET or POST which one is fast ?
difference between doget() and httpget()