//导出pdf
public String downPDF() {
// 获取页面查询参数
try {
System.out.println(exportHtmlName);
String strName = URLDecoder.decode(exportHtmlName,“UTF-8”);
System.out.println(“strName=”+strName);
HttpServletResponse response= ServletActionContext.getResponse();
HttpServletRequest request= ServletActionContext.getRequest();
// 页面对生成文件进行下载
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
File file = new File(strName);
String fileNameExp= strName.substring(strName.lastIndexOf("\")+1, strName.length());
if (file.isFile()) {
String userAgent = request.getHeader(“user-agent”).toLowerCase();
if (userAgent.contains(“msie”) || userAgent.contains(“like gecko”) ) {
// win10 ie edge 浏览器 和其他系统的ie
fileNameExp = URLEncoder.encode(fileNameExp, “UTF-8”);
} else {
// 其他
fileNameExp = new String(fileNameExp.getBytes(“utf-8”), “iso-8859-1”);
}
//解决中文乱码问题
// String strN = new String(fileNameExp.getBytes(“UTF-8”),“iso-8859-1”);
response.reset();
response.setContentType(“application/x-msdownload;charset=ISO8859-1”);
response.setHeader(“Content-Disposition”,“attachment;filename=” + fileNameExp);
bis = new BufferedInputStream(new FileInputStream(file));
bos = new BufferedOutputStream(response.getOutputStream());
int i;
while ((i = bis.read()) != -1) {
bos.write(i);
}
bos.close();
bis.close();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("下载");
return "JSONDATAS";
}