Chinese garbled characters returned from the background during SWFUpload File Upload

Source: Internet
Author: User

SWFUpload is a file upload tool developed using Flash and Javascript. Recently, when using it to upload files, it found that Chinese characters returned from the background are often garbled.

After SWFUpload is uploaded successfully, the following operations are performed on the returned results in the background:

function uploadSuccess(file, serverData) {  ......}

Here, file is the information of the uploaded file, and serverData is the data returned from the background. We found garbled Chinese Characters in serverData. The Code returned by the Struts2 Action class for processing image uploads in the background is as follows:


Later I found that something went wrong in the above area. Previously, the println method of the ServletOutputStream byte stream was used. This method will convert the serverData string to the byte stream according to the default encoding, while SWFUpload uses UTF-8 encoding, resulting in inconsistent encoding, chinese garbled characters.

Then I thought about two solutions:

1) For byte streams, manually encode serverData according to the UTF-8, and use the write method to output byte streams;


2) use the livestream and specify the encoding of the livestream as the UTF-8.


This article is from the "Learning document" blog, please be sure to keep this source

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: 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.