js(multipart/form-data)上传控件上传文件

利用js的控件进行文件上传,

java中的getFile参数值必须等于这个控件的name值。


<form id="resultForm" method="POST" enctype="multipart/form-data"
			action="${contextPath }<iconfig:constant fieldName='ddd_URL' shortClassName='Url'/>">
选择Excel文件:<input id="importExcel" type="file" size="28" name="file"
								class="input" style="height: 22px;">
<a href="#" id="FileImporting" >&nbsp;&nbsp;导入数据&nbsp;&nbsp;</a>
</form>

点击提交按钮,将上传控件的表单提交
$("#FileImporting").click(function(){
	$("#resultForm").submit();
});


	@RequestMapping(value = Url.MSYH_IMPORTING_URL)
	public String fileImport(ModelMap model, final String fileName, HttpServletRequest req, HttpServletResponse res){
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) req;
MultipartFile multipartFile = multipartRequest.getFile("file");
InputStream in = multipartFile.getInputStream();
//上面是获取到对应上传控件的流。。。。
}

你可能感兴趣的:(form)