Settings for JSP page headers when exporting Word, Excel format files in Java

Source: Internet
Author: User

In JSP, we tend to export the contents of some tables to local, which is usually the Word, Excel format files. This only needs to be set in the JSP page header and add the following code to the

Export to Excel:

<%

Response.setcontenttype ("Application/vnd.ms-excel;charset=utf-8");

Response.setheader ("Content-disposition", "Attachment;filename=test.xls");

%>

Export to Word:

<%

Response.setcontenttype ("Application/msword;charset=utf-8");

Response.setheader ("Content-disposition", "Attachment;filename=test.doc");

%>

If the above exported file in the Chinese has garbled, will charset=utf-8 to CHARSET=GBK, so that can solve the problem of Chinese garbled.

But most of the time we are the default encoding format for Charset=utf-8.

Settings for JSP page headers when exporting Word, Excel format files in Java

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.