jsp中要利用java来实现打开,可以通过浏览器打开:
以下程序实现了读宏源取某个路径下的pdf文件,并用浏览器打开:
package test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PDFServlet extends HttpServlet {
private static final long serialVersionUID = -3065671125866266804L;
public PDFServlet() {
super();
}
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("塌扒application/pdf");
FileInputStream in = new FileInputStream(new File("团绝昌d:/1.pdf"));
OutputStream out = response.getOutputStream();
byte[] b = new byte[512];
while ((in.read(b)) != -1) {
out.write(b);
}
out.flush();
in.close();
out.close();
}
public void init() throws ServletException {
}
}
直接用一个a标签 src的地址是pdf的运物派文件路径 就行了嘛
或者用js window.open(“蚂余pdf路径旁贺”)