java里怎么抛错误到页面上,java poi 导出excel错误怎么抛到页面上

java poi 导出excel异常如何抛到页面上

使用poi做的excel导出。现在遇到的问题是,如果发生异常,如何能够捕获异常后,传给页面,有一个弹出框,提示导出失败。如果没有异常就正常导出。

jsp中:

java 中处理

public String policyExportInfo(){

HttpServletResponse response = ServletActionContext.getResponse();

HttpSession session = request.getSession();

WrUser user = (WrUser) session.getAttribute("user");

GcspPolicy policy = (GcspPolicy) session.getAttribute("policy");//获取查询对象

if(user!=null&&policy!=null){

policy.setThisComCode(user.getComCode());

}

custType = user.getCustType();

String reqXML = this.getXML(custType,"POLICYEXPORT",policy);

GcspServerClient client = new GcspServerClient();

//  String xmlData1="E:\\policyReturn.txt";

// String returnValue = this.readFile(xmlData1);

String returnValue = "";

String returnValueDecompress = "";

try {

//总线保存采用GZIP压缩,并用base64转码;接收到总线返回报文后,需先使用base64解码,并解压缩

returnValue = client.requestXML(reqXML);//获取报文

byte[] b = new sun.misc.BASE64Decoder().decodeBuffer(returnValue);//使用BASE64解码

byte[] b1= client.decompress(b);//解压缩

StringUtil s= new StringUtil();

returnValueDecompress = s.byteToChar(b1, "GBK");

policyList = new ArrayList ();

String rtnPage = this.messageParsingPage(returnValueDecompress);

if(rtnPage.contains(";")){

String strTemp[] = rtnPage.split(";");

if(strTemp.length>0){

policyList = this.messageParsingPolicy(returnValueDecompress);

}

} else {

response.reset();

response.setContentType("text/html charset=UTF-8");

response.getWriter().write("

response.getWriter().write("alert('导出失败,请重试');");

response.getWriter().write("");

//            gcspException = "导出失败,请重试";

//            logger.error(gcspException);

//            return "gcspException";

}

if(policyList!= null){

HSSFWorkbook workbook;

workbook = exportExcelStyle(policyList);

ByteArrayOutputStream output = new ByteArrayOutputStream();

workbook.write(output);

output.flush();

byte[] ba = output.toByteArray();

inputStream = new ByteArrayInputStream(ba,0,ba.length);

output.close();

}else{

}

} catch (Exception e) {

response.reset();

response.setContentType("text/html charset=GBK");

try {

response.getWriter().write("

response.getWriter().write("alert('导出失败,请重试');");

response.getWriter().write("");

} catch (IOException e1) {

e1.printStackTrace();

}

logger.error(gcspException,e);

return "";

//gcspException = "导出失败,请重试";

//            return "gcspException";

}

return "exportexcel";

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值