1. 程式人生 > >liunx poi excel下載內容亂碼本地tomcat正常

liunx poi excel下載內容亂碼本地tomcat正常

結論:在jsp中加上out.clear即可(前提保證生成的excel在伺服器上是正確的,只是瀏覽器傳輸才出現亂碼)。

dowload.jsp完整程式碼

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="com.userpackage.*" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request. setCharacterEncoding("UTF-8");
//response.setHeader("Content-Type", "charset=UTF-8");
%>

<%
/*
Enumeration pNames = request.getParameterNames();
String keyStr="";
String valueStr="";
Map map = new HashMap();

while (pNames.hasMoreElements()) {
	keyStr = pNames.nextElement().toString();
	valueStr = request.getParameter(keyStr).toString().trim();
	if(!"".equals(valueStr)){
		out.println(keyStr+"=="+valueStr);
	}
}
*/
out.clear();
out
= pageContext.pushBody(); ExcelExport.export(request,response); out.println("22222"); %>

 現象:

response.reset();// 在servlet中加入,清除首部的空白行