Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTTP Status 405

 
Sophia Choi
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sophia Choi
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic