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 is the solution that ajax downloads the content of smartupload and cannot display Chinese characters?

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

AJAX download smartupload content can not show how to solve Chinese characters, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need this can come to learn, I hope you can gain something.

The code is as follows:

Server side:

public void doGet(HttpServletRequest req, HttpServletResponse resp)

throws ServletException, IOException{

req.setCharacterEncoding("GBK");

//Create a SmartUpload object

SmartUpload su = new SmartUpload();

su.initialize(this.getServletConfig(),req,resp);

//Set contentDisposition to null to prevent browsers from automatically opening files

//Make sure you click on the link to download the file. If not set, the downloaded file extension is

//doc, the browser will automatically open it with word. With pdf extension,

//The browser will open with acrobat.

su.setContentDisposition(null);

//download file

try {

su.downloadFile("D://upload/"+"test.txt");

} catch (SmartUploadException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

The code is as follows:

Client:

function getFile(){

$.get("LoadFileServlet","",function(data){

alert(data);

});

}

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