Take the 2-minute tour ×

I am uploading files using servlets. Now, i want to process some user input/form data in the same servlet. Is that possible? If, its possible means, how?

As far what i know is, doPost() method have an if condition to check whether the request contains mutilpart data and in else block the form processing. How the both if & else block getting execute? I am confused.

Any suggestions!!!

share|improve this question
You won't be able to execute both the if and else blocks in the same request. But it sounds like you don't need to - if it's a multipart post, handle it as an upload, else hand it as a form submission. –  Andrzej Doyle Nov 19 '10 at 11:15
doPost has any statements you put there. What is confusing you? if multipart, process file, process data anyway, not in else. A code snippet may be helpful here. –  khachik Nov 19 '10 at 11:16
@khachik : i am already uploading files using a servlet. Now i want to process some form data using that same servlet, while uploading file. Is it possible!! –  Tamil Vendhan Kanagaraju Nov 19 '10 at 11:23
@ Andrzej Doyle: I want to do the both in same servlet at same time. Is that possible! –  Tamil Vendhan Kanagaraju Nov 19 '10 at 11:25
@CS 1.6 Yes that is pretty possible –  Jigar Joshi Nov 19 '10 at 11:29

2 Answers 2

up vote 1 down vote accepted

Those if-else blocks are in a for or while loop over List<FileItem>, right? The loop just keeps repeating the piece of if-else code until there are no items anymore.

I must however admit that the FileItem is a misleading name. MultipartItem has been a better name.

See also:

share|improve this answer
I admit, it was my mistake!! –  Tamil Vendhan Kanagaraju Nov 20 '10 at 1:03

Since you're using Servlet 3.0, you'll be pleased to know that it comes with Asynchronous Processing. With asynchronous processing, a thread is called to handle a resource and return back to the container without being blocked.

There is a good explanation on JavaWorld which explains Asynchrous Processing. I don't know if that's what you're looking for.

share|improve this answer

Your Answer


