遇到了一个很郁闷的问题
写个servlet,用来导数据到word的,结果在ie8的情况下闪退了,在ie9情况下不会,郁闷啊。
private void statResult_sublist(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ExportBean exportBean = new ExportBean();
ByteArrayOutputStream baos = null;
OutputStream outp = null;
try {
String parentConetentId = request.getParameter("parentContentId");
EcmContent content=EcmFactory.getContentManager().getContent(parentConetentId);
if(content!=null){
request.setAttribute("sort", ContentQuerySql.ARTICLE_PUBLISH_DATE);
request.setAttribute("limit", String.valueOf(Integer.MAX_VALUE-1));
QueryResult qr = EcmFactory.getContentProcessHelper().doSubList(request);
new AfterQueryAttachAttribute().process(qr);
List dataList = qr.getData();
if (dataList == null) {
dataList = new ArrayList();
}
String fileName = new String((content.getTitle() + "统计数据.doc").getBytes("GBK"),"ISO8859_1");
baos = exportBean.createDocForStatResultSubContentListStatistic(content, dataList);
response.setContentType("application/x-download");
response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
response.setContentType("text/doc;charset=utf-8");
// 将baos字节流输出给用户下载
outp = response.getOutputStream();
outp.write(baos.toByteArray());
outp.flush();
}
} catch (Exception e) {
System.out.println("Error!");
e.printStackTrace();
} finally {
if (outp != null) {
outp.close();
outp = null;
}
}
}
于是乎,我干了点其他事情,
在当前页面做了个隐藏form,用来跳转
<div> <form name="exportWordForm" >
<input type="hidden" name="function" id="function" value="statResult_sublist">
<input type="hidden" name="parentContentId" id="parentContentId" value="<%=parentContentId %>">
<input type="hidden" name="categoryId" id="categoryId" value="<%=categoryId %>">
</form></div>
然后再在js控制了让它跳到另外一个页面去执行导出
var url="<%=request.getContextPath()%>/doExportDocumentForFeedBack.do";
//document.getElementById("exportWordForm").action = url;
//document.getElementById("exportWordForm").target = "_blank";
//document.getElementById("exportWordForm").submit();
window.open("exportWord.jsp?parentContentId=<%=parentContentId%>");
最后新建了一个页面,只是为了让它自动导出
<%@ page language="java" pageEncoding="utf-8"%>
<%
String parentContentId = request.getParameter("parentContentId");
%>
<html>
<head>
</head>
<body>
<form name="exportWordForm" >
<input type="hidden" name="function" id="function" value="statResult_sublist">
<input type="hidden" name="parentContentId" id="parentContentId" value="<%=parentContentId %>">
</form>
<script type="text/javascript">
var url="<%=request.getContextPath()%>/doExportDocumentForFeedBack.do";
document.getElementById("exportWordForm").action = url;
//document.getElementById("exportWordForm").target = "_blank";
document.getElementById("exportWordForm").submit();
//window.close();
</script>
</body>
</html>
YES,这下不会闪退了,但是会留下一个空白的页面,得手动关闭,有悲剧了