开发者

how to get values from a multipart request in java

开发者 https://www.devze.com 2023-03-07 11:37 出处:网络
Here is the form submission part var form=document.forms[\"mainForm\"]; form.setAttribute(\"action\",url_action);

Here is the form submission part

var form=document.forms["mainForm"];
form.setAttribute("action",url_action);
form.setAttribute("metho开发者_如何学JAVAd","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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消