I am using Spring framework and able to upload the file on server successfully.
<form action="upload.do" method="post" enctype="multipart/form-data">
<input type="text" name="description" />
<input type="file" name="locationMapFile" />
........
........
<input type="submit" />
</form>
// controller layer
@RequestMapping(value = "/upload.do", method = {RequestMethod.POST})
public String addEditLocationToCompany(Model model
,@RequestParam("description")String desc
,@RequestParam(value="locationMapFile", required=false) CommonsMultipartFile locationMapFileData)
{
}
till now everything is fine. Now i am adding some dynamic hidden parameter on form using the javascript.
Note : as per setting i am defining the dynamic parameter name and its value like
<input type="hidden" name="setting_14" value="abcd">
<input type="hidden" name="setting_5" value="xyz">
How can i fetch these dynamic parameter into Spring controller.
I have tried
(1) I can not use the @RequestParam since do not want to hard code the parameter name
(2) request.getParameter() : not working and returning null since this is multipart/form-data request
(3) I have used this link How to upload files to server using JSP/Servlet? and tried
List<FileItem> items =
new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
but in spring controller items is null. so not able to iterate it and fetch the FileItem from it.
Please help me to find out the way to get the dynamic parameter's value into the spring framework.
You can use MultipartHttpServletRequest to get the request parameters:
@RequestMapping(value = "/upload.do", method = {RequestMethod.POST})
public String addEditLocationToCompany(Model model
,@RequestParam("description")String desc
,@RequestParam(value="locationMapFile", required=false) CommonsMultipartFile locationMapFileData, MultipartHttpServletRequest mrequest)
{
String value = mrequest.getParameter("setting_14");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With