Spring MVC Excel的上传和解析,后台无法获取文件名,控指针错误
这几天写Excel上传解析,获取文件流后直接解析不保存。但是后台获取不到文件。新手一个,了解浅显,催着交。还希望大家指点指点。下面是代码,也不怕大家笑话JSP:<divi...
这几天写Excel 上传解析,获取文件流后直接解析不保存。但是后台获取不到文件。新手一个,了解浅显,催着交。还希望大家指点指点。下面是代码,也不怕大家笑话
JSP:
<div id="form">
<form method='post' id='uploadForm' runat="server">
<input type='file' name='file_head' id='file_head'/>
<input type='button' value="上传"onClick="upload()"/>
</form>
</div>
controller:
@RequestMapping("importExcel")
@ResponseBody
public String importExcel(ModelMap mv,@RequestParam(value="uploadFile",required=false) MultipartFile file,HttpServletRequest request,HttpServletResponse response)
System.out.println("开始");
String path = request.getSession().getServletContext().getRealPath("upload");
//无法获取文件流,抛出空指针异常
String fileName = file.getOriginalFilename();
System.out.println(path);
File targetFile = new File(path, fileName); 展开
JSP:
<div id="form">
<form method='post' id='uploadForm' runat="server">
<input type='file' name='file_head' id='file_head'/>
<input type='button' value="上传"onClick="upload()"/>
</form>
</div>
controller:
@RequestMapping("importExcel")
@ResponseBody
public String importExcel(ModelMap mv,@RequestParam(value="uploadFile",required=false) MultipartFile file,HttpServletRequest request,HttpServletResponse response)
System.out.println("开始");
String path = request.getSession().getServletContext().getRealPath("upload");
//无法获取文件流,抛出空指针异常
String fileName = file.getOriginalFilename();
System.out.println(path);
File targetFile = new File(path, fileName); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询