后台代码如下:
@SuppressWarnings({ "finally", "unchecked", "null", "rawtypes" })
@RequestMapping(value = "/jhxz", produces = "application/json")
private List jhxz(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map map = new HashMap();
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEncoding("UTF-8");
File fil=null;
List<FileItem> items = null;
try {
items = upload.parseRequest(request); // 获得前台提交过来的信息,两类:文件、form表单
} catch (FileUploadException e) {
e.printStackTrace();
}
File file = new File("D://2.dat");
if (!Util.isNullOrEmpty(items)) {
Iterator<FileItem> itr = items.iterator();
while (itr.hasNext()) {
FileItem item = (FileItem) itr.next();
if (item.isFormField()) {//将前台拿到的文件进行处理保存到文帝
//