JSP Export Excel template __js

Source: Internet
Author: User
Tags base64

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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.