In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about how to garbled ServletResponse download files. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Generally speaking, there are two ways to solve garbled code:
1. Encode the file name (including Chinese characters) into UTF-8
String downloadOrigalFile = "Test file garbled .xlsx"
String downloadFileName = java.net.URLEncoder.encode (downloadOrigalFile, "UTF-8")
Response.setHeader ("Content-Disposition", "filename=" + downloadFileName)
If there is a space in the file name, you need to replace the space with the space under% 20diem UTFmur8 + for space.
DownloadFileName = downloadFileName.replace ("+", "% 20")
2. Encode the file name as ISO-8859-1 (because the default encoding is ISO-8859-1)
String downloadOrigalFile = "Test file garbled .xlsx"
Final String LOCALE_ENCODING = "gb2312"
/ / LOCALE_ENCODING=gb2312 here: you can usually use the System.getProperties () of java to traverse and get
/ / generally, there are two values that may be related to this. Please refer to the actual situation.
/ / sun.jnu.encoding=GBK
/ / file.encoding=UTF-8
Final String DEFAULT_ENCODING = "ISO-8859-1"
String downloadFileName = new String (downloadOrigalFile.getBytes (LOCALE_ENCODING), DEFAULT_ENCODING)
If there is a space in the file name, you need to replace the space with% 20
DownloadFileName = downloadFileName.replace ("", "% 20")
/ / if the getBytes () here does not specify a code, there may be problems when crossing platforms. It is recommended to specify a code clearly.
Response.setHeader ("Content-Disposition", "filename=" + downloadFileName)
=
3. If you want to display Chinese in the browser address, you generally need to modify the default code URIEncoding= "UTF-8" of the web container.
(that is, download files directly by get)
For example, the tomcat container is added in the following location in TOMCAT_HOME/conf/server.xml
4. Special coding commonly used in URL
The + sign in + URL indicates space 2B.
Spaces in the space URL can be signed with a + sign or encoded with% 20
/ separate directories and subdirectories% 2F
? Separate the actual URL and parameter 3F
Specify special character 25
# indicates bookmark 23
Delimiter% 26 between parameters specified in & URL
= the value of the parameter specified in URL 3D
Thank you for reading! This is the end of the article on "what to do about garbled ServletResponse downloads". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.