Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to open a file from server in IE using jsp

 
sabapathi krishnan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

I am facing a problem when created one jsp to open a file from my system in IE.
If anyone can solve this problem please help


<html>
<head><title>Support Overview</title></head>
<body>
<%
response.reset();
response.setHeader ("Content-Disposition", "inline;filename=Saba_PhBill.pdf");


File file = new File("D:\\DEVCODE\\FT\\CoreFT\\Product\\onfn\\2012\\11\\26\\99998018_IDV_2012_11_12_02_50_21_6925143_Saba_PhBill.pdf");

//OPen an input stream to the file and post the file contents thru the
//servlet output stream to the browser
InputStream in = new FileInputStream(file);
ServletOutputStream outs = response.getOutputStream();

int bit = 256;
try {
while ((bit) >= 0) {
bit = in.read();
outs.write(bit);
}
} catch (IOException ioe) {
ioe.printStackTrace(System.out);
}finally{
outs.flush();
outs.close();
in.close();
}
%>
</body>
</html>


this is my jsp which i created for this case
 
Rajdeep Biswas
Ranch Hand
Posts: 206
1
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, welcome to the ranch :)
I am just an amateur in JSP, so no solution from my side. But I ponder that the code is executed on server side, and server does not knows the exact location where to find "D:\\DEVCODE\\FT\\CoreFT\\Product\\onfn\\2012\\11\\26\\99998018_IDV_2012_11_12_02_50_21_6925143_Saba_PhBill.pdf"!!
So, it must first connect to local system. I think Javascript (ajax in someone's infinete wisdom) might have some solution!
 
sabapathi krishnan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i can open a pdf file but i couldn't read the text because it is in encoded format.
If I use this response.setHeader ("Content-Disposition", "attachment;filename=Saba_PhBill.pdf"); instead of "inline" it is asking for open or download option.
but my requirement is to open a file in browser when i run the jsp
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sabapathi krishnan wrote:my requirement is to open a file in browser when i run the jsp

That can't be a requirement, because that is entirely up to the way the browser is configured. Whether the browser opens it, saves it, or displays a dialog asking the user what to do is entirely determined by the browser settings; the web app has no control over that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic