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