在线预览PDF文件步骤:
1、页面contentType为text/html
<%@ page contentType="text/html; charset=gbk"
pageEncoding="UTF-8"%>
2、生成PDF文件路径
String filePath =" http://locast:8080/myproject/ext/temp/test.pdf";
3、请求转发,访问PDF文件
if (filepath.endsWith(".pdf")) {
response.setContentType("application/pdf");//很重要,不然直接打开pdf会乱码
response.sendRedirect(filepath);
}