Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Paul Featherstone

Greenhorn
+ Follow
since Mar 22, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Paul Featherstone

Hi,

I have developed a simple file upload servlet in Eclipse, all works fine using test version of a Java EE web project running Tomcat V7.

When I have switched to my non testing version project using Tomcat v6 (it needs to be this v as specified in project requirements) the script will not run. After hours looking at this I have found the following:

1) The Commons File Upload library was not saved as part of the v7 project - I have now added this to the build path saved within the Tomcat 6 folder (should this in-fact be saved in WEB-INF/lib or does this not really matter?)
2) Eclipse is prompting me to point to the tomcat-coyote.jar file in my Tomcat V7 folder
3) Following the above fix from Eclipse causes a java.lang.NoClassDefFoundError - this makes sense as I clearly don't want to be using two sets of files for V6/V7

The odd thing is that out of the following class imports:



The first two are fine but the second two cause issues.

It seems that compiling on v7 and switching to v6 to execute has caused these issues, is it that DiskFileItemFactory and ServletFileUpload in the Commons File Upload library are not supported on Tomcat v6 or is there another explanation?

Any pointers would be much appreciated, thanks in advance!

Regards,
Paul

Hi,

I'm developing a simple login form using jsp and a servlet which performs some basic validation/authentication prior to redirecting to the home.jsp page. I am having issues and have stripped the servlet right back to basics but am still getting the same error message:

The method isEmpty() is undefined for the type String

I know that this exception is caused by use of isEmpty without the having 1.6 jre (I have 1.5 on my mac) but I have now completely removed any mention of the isEmpty method so how can the same exception be thrown? I had previously tried using StringUtils.isEmpty(String)..nothing seems to make any difference, when the form is posted it always throws the same exception, sure it's something silly (as ever!!).

I have substituted a simple validation script I found on another thread on the forum to see if it solved the problem..anyway, here is the code as it currently stands (routing login.jsp via LoginServlet.java)..



Any pointers would be much appreciated. Thanks for your help in advance.

Regards,
Paul
10 years ago
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
10 years ago
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
10 years ago
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
10 years ago