Java file download file name garbled

Source: Internet
Author: User
Tags base64
What is the reason for garbled characters?
Each browser does not have the same encoding, Firefox uses base64.ie and Google uses URL encoding

So when we set the response header,
Content-type Getservletcontext (). Getminetype (filename);
Content-disposition accachment;filename= encoded filename

URL encoding
name = Urlencoder.encode (filename, "UTF-8");

Base64 encoding
/**

  • The name of the incoming file for BASE64 encoding
  • @param fileName
  • @return
    */
    public string Base64encodefilename (string fileName) {
    Base64encoder Base64encoder = new Base64encoder ();
    try {
    Return "=? UTF-8? B? "
    • New String (Base64encoder.encode (fileName
      . GetBytes ("UTF-8")) + "? =";
      } catch (Unsupportedencodingexception e) {
      E.printstacktrace ();
      throw new RuntimeException (e);
      }
      }

Java file download file name garbled

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.