<a href2='javascript:;' class='view' href='<%=path%>/officefile/pdfShow.action?pdf_path="+pdfpath+"' target='_blank'>在线预览PDF</a>
以上是jsp代码
@RequestMapping("/pdfShow")
public void pdfShow(HttpServletRequest request, HttpServletResponse response, String pdfPath) throws Exception {
request.setCharacterEncoding("UTF-8");
// String ctxPath = request.getSession().getServletContext().getRealPath("");
response.setContentType("application/pdf");
FileInputStream in = new FileInputStream(new File(pdfPath));
OutputStream out = response.getOutputStream();
byte[] b = new byte[512];
while ((in.read(b)) != -1) {
out.write(b);
}
out.flush();
in.close();
out.close();
}
以上后台调用代码