0

Here is the form submission part

var form=document.forms["mainForm"];
form.setAttribute("action",url_action);
form.setAttribute("method","post");
form.setAttribute("enctype","multipart/form-data");
form.setAttribute("encoding","multipart/form-data");
form.submit();

Now how can I get all the parameters or form input type names and corresponding values to a map in servlet?

Map example:

name=Abhishek
age=25
filename=abc.txt
AabinGunz
  • 12,109
  • 54
  • 146
  • 218
  • Missed multi part : Duplicates this somehow :http://stackoverflow.com/questions/1748259/get-form-parameters-from-multipart-request-without-getting-the-files – jmj May 19 '11 at 09:28
  • And http://stackoverflow.com/questions/2422468/how-to-upload-files-in-jsp-servlet/2424824#2424824 – BalusC May 19 '11 at 13:08

1 Answers1

2

Use Commons / FileUpload:

The simplest case The simplest usage scenario is the following: Uploaded items should be retained in memory as long as they are reasonably small. Larger items should be written to a temporary file on disk. Very large upload requests should not be permitted. The built-in defaults for the maximum size of an item to be retained in memory, the maximum permitted size of an upload request, and the location of temporary files are acceptable. Handling a request in this scenario couldn't be much simpler:

// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();

// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);

// Parse the request
List /* FileItem */ items = upload.parseRequest(request);

Source: Using FileUpload

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588