Java POI export Excel response.setheader Settings export file name grab package illegal and process export FileName as action method name

Source: Internet
Author: User

Problem occurs 1:

Use POI to export Excel under Spring MVC Framework, set export file name: Response.setheader ("Content-disposition", "Attachment;filename=" +sourceid+ "_" + datestring+ ". xls");

When this method is used to catch a package test, it shows that the bug URL is not valid.

Workaround: String filenmae = Urlencoder.encode for "attachment;filename=" +sourceid+ "_" +datestring+ ". xls" ("attachment; Filename= "+sourceid+" _ "+datestring+". xls ", StandardCharsets.UTF_8.displayName ()); Again Response.setheader ("Content-disposition", Filenmae);

However, a new problem occurs 2:poi when you export Excel, the export file name is the action method name.

Workaround: Use new String (byte[], "utf-8");

String fileName = "Attachment;filename=" +sourceid+ "_" +datestring+ ". xls";
Response.setheader ("Content-disposition", New String (Filename.getbytes (), "Utf-8"));

Final Solution: Grab the package test pass.

Java POI export Excel response.setheader Settings export file name grab package illegal and process export FileName as action method name

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.