Opening File in viewer outside browser

I have a JSP page where I have a hyperlink to view a file. The file could be a word doc, or a pdf doc. If the user clicks on the link the document is opened in the browser. Is there a way to open it outside the browser by launching the corresponding viewer. The browser view should remain the same as it was befoore the link was clicked.

here is the simple JSP (only posting the relevant code)

   <a href="Popup">Click here to download</a>

The servlet that writes the file

public class Popup extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException   {

            String fileName ="XMLAppuserguide.pdf";
            ServletOutputStream sos = null;
        sos = response.getOutputStream();
            File file = new File(fileName);
            FileInputStream fis = new FileInputStream(file);

            int  b =;
        while (b!=-1) {

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

<a href="1.exe">Click here to download</a>
should work
thomas908Author Commented:
>><a href="1.exe">Click here to download</a>
I need to do it through a servet, since there is some other logic in servlet that I have not posted.
ZvonkoSystems architectCommented:
Like this:

<a href="Popup" target="_blank" >Click here to download</a>

The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

ZvonkoSystems architectCommented:
And if you want to open and reuse one single popup window on every link klick, then give the popup window a Name:

<a href="Popup" target="myPop" >Click here to download</a>

thomas908Author Commented:
<<<a href="Popup" target="_blank" >Click here to download</a>

But this still opens it in the browser. I want the application to be launched directly.
thomas908Author Commented:
To be more precise with what I posted above, there'll be only .tiff images that need to be opened in the microsoft image viewer. There are no pdf and msword files, I posted that just as an example.
thomas908Author Commented:
When I give the path to .tif image in my servlet, then I get an open/save dialog box. Is there a way to compress this dialog box, so that the image directly opens in the viewer.
Michel PlungjanIT ExpertCommented:
response.setContentDisposition("attachment; filename=\""+filename+"\"");
thomas908Author Commented:
Getting this error cannot resolve symbol
symbol  : method setContentDisposition (java.lang.String)
location: interface javax.servlet.http.HttpServletResponse
        response.setContentDisposition("attachment; filename=\""+file.getName()+
1 error
Michel PlungjanIT ExpertCommented:
response.setHeader("Content-disposition","attachment; filename=\""+file.getName()+"\"");

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
>> I need to do it through a servet, since there is some other logic in servlet that I have not posted.

Try a download servlet like this:
well as everybody above has said.. you will have to set the contnet type of your response data depending upon what kind of data you are sending to the client.

for example for a MS-word file you will have to do

for a gif image it has to be..


and so on..

you will have to cover a lot of mime types to have it all covered.
ZvonkoSystems architectCommented:
Did you try:

            String fileName ="myImage.tif";

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.