private InputStream inputStream;
private String fileName;
@Action(results = { @Result(name = "success", type = "stream", params = { "contentType",
"application/x-msdownload,charset=GBK", "inputName", "inputStream", "contentDisposition",
"attachment;filename=\"${fileName}\"","contentCharSet","GBK" }) })
try {
fileName = new String(("订餐列表" + String.format("%tF", new Date()) + ".csv").getBytes("GBK"), "ISO8859-1");
inputStream = new BufferedInputStream(new ByteArrayInputStream(res.getBytes("gbk")));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
public InputStream getInputStream() {
return inputStream;
}
public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
如果乱码,检查是否将编码格式转换为gbk。以上为代码片段