I have an application that allows people to submit multiple files via the web. I'm using a jQuery multiple file upload
plugin on the front-end and I'm using Apache's FileUpload on the backend in my servlet.
I'm running into a problem where if the user tries to upload a file that exceeds the maximum size, I get an exception
and I can't seem to trap it. That means I can't display a meaningful error back to the user.
I've done some Google searches and found some code that looks like it may work, but it's way too complex for me
to even begin understanding and most of it seems to involve either Struts, myFaces or Spring, none of which I'm
Any ideas on how I can gracefully notify the user that the file is too large to upload?
Are you sure it is not catching it? Did you try it in the debugger or carefully examine the log output?
What exactly happens when the size limit is exceeded? It looks like you are just returning like normal but would then get a null pointer because your fileItems would be null.
I plugged your catch blocks into my working file upload's try and it caught just fine on the first catch:
posted 10 years ago
I tried it again, and made a few changes and I got it to the point where it does catch it, but not in the way I expected. Usually I can catch the error and handle it somehow and return gracefully to the user. In this case, it catches the exception, but there doesn't seem to be any way to give the user back their session variables, or recover their data. The best I can do it present the user with the error and the web form that is missing all the text they entered. I'll have to work at it some more I guess. Maybe if I move the upload fields to a separate form and submit them separately from the rest of the form I can work with that somehow.