File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes How to open file 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 file using jsp?" Watch "How to open file using jsp?" New topic

How to open file using jsp?

Rajasekhar Eega

Joined: Jul 31, 2012
Posts: 11

Here is my code to download a file using jsp. Its working. But what i need is just to open the file. No need to show the options of saving. just to open. Please help me, what modifications I have to do here???

Thank you

Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

While setting the header, replace "attachment" with "inline" so that the browser will try to open the file with default application in your machine.

Thanks & Regards, Sumeet
SCJP 1.4, SCWCD 5, LinkedIn Profile
Matthew Brown

Joined: Apr 06, 2010
Posts: 4544

You really, really shouldn't be doing any of that in a JSP though. That all belongs in a servlet.
SaiManasa Dasari
Ranch Hand

Joined: Aug 21, 2012
Posts: 32
Hi All,

Even using
it showing open/save dialogbox in firefox and its downloading in chrome browser..
Can anyone please help me what changes need to get open the file directly without open/save dialog box.please.

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Check the browser settings; there's nothing the web app can do about that.

And do yourself a favor by taking Matthew's advice - using a JSP for this will lead to tears. JSPs are for emitting character data, not for processing data, not for file or DB I/O, and not for handling binary data.
I agree. Here's the link:
subject: How to open file using jsp?
It's not a secret anymore!