Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

HTTP Status 405 - HTTP method GET is not supported by this URL

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm writing a basic java servlet which uploads files to an 'uploads' folder on my local disk (I'm on mac OSx10). There seems to be an issue with the POST request in the form, when I implement a doPost method in the servlet. I know that you can override the methods to accept either get/post but I assume I shouldn't need to do that as I use the Post action in the client form. When compiled I get the error message:

HTTP Status 405 - HTTP method GET is not supported by this URL

Here is the code (sorry couldn't see an option to tag as HTML code?):

Form:

<form enctype="multipart/form-data“ method="POST" action="FileUploadServlet">
<input type="file" name="file"><br /> <br /> <input type="submit" value="upload the file">
</form>

Servlet:



If I change the form method in the form to Get then the code compiles okay e.g. http://localhost:8080/CMS/FileUploadServlet?file=atextfile.txt but I get the "Failed to upload file. Sorry!" exception. I'm just getting used to debugging - hasn't told me much so far I'm afraid.

So my questions are:
1) Why does form method get and servlet post method compile okay but not post and post?
2) Is there anything obvious I am missing which is causing the file upload to fail with get/post - I've checked the folder access is okay for where I am trying to write the file to but it doesn't seem to throw that exception anyway??

Thanks for your help in advance, I am going round in circles here! I know this will be something stupid I have done/missed.

Regards,
Paul
 
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
see this thread https://coderanch.com/t/529961/Servlets/java/Getting-Error-HTTP-Status-HTTP
 
Paul Featherstone
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sudhir,

Thanks for the quick response.

So, in this servlet you can't only have a doPost method, a doGet method is needed too. That makes sense, page request and form submission.

Tried again and white screen, still seems to be an issue and no error message this time??!

Paul
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are not forced to declare any of doGet or doPost methods. That depends on how you are planning to use that servlet.
If you want your servlets to support HTTP Get method (eg when user directly hit the url in browser) implement doGet() or you will get that error.
If you want your servlet to just support http post mehod (eg a form with method=post), you don't need doGet and you can declare just doPost method.


i hope you get the point :-

- If no doGet() - trying to access the servlet using http get method would result in 405
- if no doPost() - HTTP post request would result in 405
 
Paul Featherstone
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I fixed the issue, thanks for clarification on doGet & doPost - it is as I thought. The only thing I can see that caused the issues is trying to output html in FileUploadException e in the catch blocks.

cheers
paul
reply
    Bookmark Topic Watch Topic
  • New Topic