顯示PDF

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<%@ page language="java" import="

java.io.FileInputStream,

java.io.DataInputStream,

java.io.DataOutputStream,

java.io.File"

pageEncoding="UTF-8"%>

<%

File file = new File("檔案路徑");

out.clear();

out = pageContext.pushBody();

response.setContentType("application/pdf");

try {

if (file.exists()) {

DataOutputStream temps = new DataOutputStream(response.getOutputStream());

DataInputStream in = new DataInputStream(new FileInputStream(file.getPath()));

byte[] b = new byte[2048];

while ((in.read(b)) != -1) {

temps.write(b);

temps.flush();

}

in.close();

temps.close();

} else {

System.out.println("文件不存在!");

}

} catch (Exception e) {

System.out.println(e.toString());

}

%>

<html>

<head>

<title>開啟PDF</title>

</head>

<body>

<br>

</body>

</html>