aspose file tools*
The moose likes JSP and the fly likes how to open a file from server in IE using jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how to open a file from server in IE using jsp" Watch "how to open a file from server in IE using jsp" New topic
Author

how to open a file from server in IE using jsp

sabapathi krishnan
Greenhorn

Joined: Dec 06, 2012
Posts: 2
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

Joined: Mar 26, 2012
Posts: 186

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!


The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
sabapathi krishnan
Greenhorn

Joined: Dec 06, 2012
Posts: 2
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
Marshal

Joined: Mar 22, 2005
Posts: 39550
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to open a file from server in IE using jsp
 
Similar Threads
Very basic question about using JSTL
servlet mapping
How to Get Data Into Comobox From Databse Using Hibernate in JSP Page?
Problem with sessions: Always getting old session id.
Jboss 5.1.0 jsp:root not working