excel导入抛异常页面无提示,无论是抛异常还是返回ajaxjson都...
jsp用的公用导入excel页面webapp/webpage/common/upload/pub_excel_upload.jsp 无论是抛异常还是返回ajaxjson都不起作用<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>通用Excel导入${controller_name}</title>
<t:base type="jquery,easyui,tools"></t:base>
</head>
<body style="overflow-y: hidden" scroll="no">
<t:formvalid formid="formobj" layout="div" dialog="true" beforeSubmit="upload">
<fieldset class="step">
<div class="form"><t:upload name="fiels" buttonText="选择要导入的文件" uploader="${controller_name}.do;jsessionid=${pageContext.session.id}?importExcel=true" extend="*.xls;*.xlsx" id="file_upload" formData="documentTitle"></t:upload></div>
<div class="form" id="filediv" style="height: 50px"></div>
</fieldset>
</t:formvalid>
</body>
</html>
后台正常抛异常返回ajaxjson 无论是抛异常还是返回ajaxjson都不起作用
/**
* 导入功能跳转
*
* @return
*/
@RequestMapping(params = "upload")
public ModelAndView upload(HttpServletRequest req) {
req.setAttribute("controller_name","ceBfCkglController");
return new ModelAndView("common/upload/pub_excel_upload");
}
@RequestMapping(params = "doAdd")
@ResponseBody
public AjaxJson doAdd(CeBfCkglEntity ceBfCkgl, HttpServletRequest request) {
String message = null;
AjaxJson j = new AjaxJson();
message = "添加成功";
try{
_doInsert(ceBfCkgl);
ceBfCkglService.save(ceBfCkgl);
systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
}catch(Exception e){
e.printStackTrace();
j.setMsg(e.getMessage());
return j;
// e.printStackTrace();
// message = "添加失败";
// throw new BusinessException(e.getMessage());//无论是抛异常还是返回ajaxjson都不起作用
}
j.setMsg(message);
return j;
}
参考这个写法@SuppressWarnings("unchecked")
@RequestMapping(params = "importExcel", method = RequestMethod.POST)
@ResponseBody
public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
AjaxJson j = new AjaxJson();
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象
ImportParams params = new ImportParams();
params.setTitleRows(2);
params.setHeadRows(1);
params.setNeedSave(true);
try {
List<JeecgDemoEntity> listJeecgDemoEntitys = ExcelImportUtil.importExcel(file.getInputStream(),JeecgDemoEntity.class,params);
for (JeecgDemoEntity jeecgDemo : listJeecgDemoEntitys) {
jeecgDemoService.save(jeecgDemo);
}
j.setMsg("文件导入成功!");
} catch (Exception e) {
j.setMsg("文件导入失败!");
logger.error(ExceptionUtil.getExceptionMessage(e));
}finally{
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return j;
}
页:
[1]