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