I downloaded an Excel file yesterday. The downloaded Chinese file name was garbled, but the content was not garbled. I tried many methods on the Internet and did not succeed. Finally, I found a solution.
1. Zero Configuration, nothing
@ Result (name = "success", type = "stream", Params = {"inputname", "downloadfile", "contenttype", "application/vnd. MS-Excel; charset = ISO8859-1 "," contentdisposition "," attachment; filename =$ {filename }"})
2. The get Method for file names is important
Private string filename;
Public void setfilename (string filename ){
This. filename = filename;
}
Public String getfilename () throws unsupportedencodingexception {
String enablefilename = "=? UTF-8? B? "+ (New string (base64.encode (" file name .xls ". getbytes (" UTF-8 ") + "? = ";
Return enablefilename;
}
3. inputstream
Public inputstream getdownloadfile () throws exception {
Try {
String Path = "document materials" + file. Separator + "template" + file. Separator + "file name .xls ";
System. Out. println (PATH );
Inputstream in = servletactioncontext. getservletcontext (). getresourceasstream ("\" + path );
Return in;
} Catch (exception e ){
E. printstacktrace ();
Return NULL;
}
}