可能重复:
how to display a pdf file in jsp using servlet在浏览器中显示pdf文件?
我从数据库中检索的PDF文件,并把它放在一个文件中像这样
String str="select * from files where name='Security.pdf';";
Statement stmt2= conn.createStatement
(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = stmt2.executeQuery(str);
while(rs.next())
{
InputStream input = rs.getBinaryStream("content");
//to create file
File f=new File("c:/pdfile.pdf");
OutputStream out=new FileOutputStream(f);
byte buf[]=new byte[1024];
int len;
while((len=input.read(buf))>0)
out.write(buf,0,len);
out.close();
input.close();
System.out.println("\nFile is created..");
}
现在,这是在服务器端。在我的客户端,每当用户点击一个链接时,我的jsp页面上应该显示一个链接 href = pdf(pdf是我的servlet名称),我应该在客户端的浏览器上显示从数据库检索到的文件。
我该怎么办?
对不起苏拉杰。我不是在这里写你的代码 – ganesshkumar 2012-04-27 07:04:34
如果我在Mozilla中显示“application/pdf”,但在Chrome浏览器中没有显示:( – suraj 2012-04-27 07:14:06
你正在使用哪个chrome版本? – ganesshkumar 2012-04-27 07:20:39