Home >Operation and Maintenance >Linux Operation and Maintenance >The local tomcat is normal, but the content is garbled when downloading liunx poi excel

The local tomcat is normal, but the content is garbled when downloading liunx poi excel

青灯夜游
青灯夜游forward
2018-10-17 15:14:263216browse

This article will introduce to you the solution to the problem that the local tomcat is normal, but the content is garbled when downloading liunx poi excel. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Conclusion: Just add out.clear to jsp (the premise is to ensure that the generated excel is correct on the server, and garbled characters appear only when the browser transmits it).

dowload.jsp complete code

<%@ 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");
%>

Phenomenon:

response.reset();// Add in servlet to clear the blank line in the header

The above is the detailed content of The local tomcat is normal, but the content is garbled when downloading liunx poi excel. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete