0

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!!!

  • 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!! –  Nov 19 '10 at 11:23
  • @ Andrzej Doyle: I want to do the both in same servlet at same time. Is that possible! –  Nov 19 '10 at 11:25
  • @CS 1.6 Yes that is pretty possible – jmj Nov 19 '10 at 11:29
  • @org.life.java: How? Can you explain me!! –  Nov 19 '10 at 11:32

2 Answers2

1

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

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.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228