Recently encountered a problem, in the JSP page export Excel, only export 1 lines no garbled, export 2 lines of time, there are garbled, and then I have a list of exports, in the penultimate 2nd column when garbled, online search materials, have not how to solve my problem, Most of the internet is to solve the JSP Chinese garbled posts, with me this is still a little different. Later found, do not know who wrote the code, due to the export, it is possible to export word is also possible to export Excel, the previous person in the code to judge a moment:
<%
if ("word". Equals (DocType)) {
%>
<meta http-equiv= "Content-type" content= "text/html;charset=gb2312" >
<body>
<style>
<!--
. td_border1{
Border-right:1 solid #000;
Border-bottom:1 solid #000;
}
-->
</style>
<%
}
Yes, this is the code, if you are exporting word
Note: JSP export Excel, if the other settings are set up, there are garbled, remember to add: <meta http-equiv= "Content-type" content= "text/html;charset=gb2312" >
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%> <%@ page import= " Org.apache.commons.codec.binary.Base64 "%> <%@ taglib prefix=" s "uri="/struts-tags "%> <%@ page import=" Java.net.URLEncoder "%> <%@ taglib uri=" Http://java.sun.com/jsp/jstl/core "prefix=" C "%> <%@ taglib prefix= "FMT" uri= "http://java.sun.com/jsp/jstl/fmt"%> <%@ taglib prefix= "Limit" uri= "http://www.yineng.com/limit"% > <%@ taglib prefix= "FN" uri= "http://java.sun.com/jsp/jstl/functions"%> <%@ taglib prefix= "EV" uri= "http:/"
/www.yineng.com/enumvalue "%> <% String Path = Request.getcontextpath ();
Response.setcontenttype ("Application/vnd.ms-excel;charset=utf-8");
String excelname = "Student Credit compliance Situation";
Garbled solution, according to the user's browser to obtain download information String Agent = (string) request.getheader ("User-agent"); if (Agent!= null && agent.indexof ("msie") = = 1) {//FF Excelname = "=? UTF-8?
B? "+ (New String (Base64.encodebase64 excelname.getbytes (" UTF-8 "))) +"? = "; ResPonse.setheader ("Content-disposition", "attachment;
Filename= "+ Excelname +". xls ");
else {//IE excelname = new String (excelname.getbytes ("GBK"), "iso-8859-1"); Response.setheader ("Content-disposition", "attachment;
Filename= "+ excelname+" ". xls"); }%>