Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What if the response file stream output file name is not displayed in Chinese?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "response file stream output file name Chinese does not display how to do," in daily operation, I believe many people in response file stream output file name Chinese does not display how to do the problem there are doubts, small editor consulted all kinds of information, sorted out simple and easy to use operation methods, hope to answer "response file stream output file name Chinese does not display how to do" doubts helpful! Next, please follow the small series to learn together!

File stream output file name Chinese not displayed

response Return file stream with response.setHeader("Content-disposition", "attachment; filename="+fileName); Result Chinese name with "-" slide down display.

response. setCharacteristEncoding ("UTF-8");response.setContentType("text/html;charset= UTF-8");response.setLocale(new java.util.Locale("zh","CN"));

The reason is that these operations are encoding settings for the returned content, and here I set the file name to the header;

solution

Convert file names to ASCII ~

As follows:

//10,000 lines of code do not show OutputStream output = null; try { response.reset(); response.setContentType("application/msexcel;charset=UTF-8");// response.setCharacterEncoding("UTF-8"); fileName = URLEncoder.encode(fileName,"UTF-8"); output = response.getOutputStream(); response.setHeader("Content-disposition", "attachment; filename="+fileName); wb.write(output); if(output != null) output.close(); } catch (IOException e) { // TODO e.printStackTrace(); }response Download Chinese file name garbled FileInfo info = new FileInfo (strFilePath);long fileSize = info.Length;Response.Clear();Response.Buffer = true;Response.ContentType = "application/x-zip-compressed";Response.AddHeader ("Accept-Language", "zh-cn");Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpContext.Current.Server.UrlEncode(info.Name));//does not specify Content-Length If Flush is used, download progress will not be displayed Response.AddHeader("Content-Length", fileSize.ToString());Response.TransmitFile(strFilePath, 0, fileSize);Response.Flush();Response.Close();info.Delete(); At this point, the study of "response file stream output file name Chinese does not display" is over, hoping to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report