• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5025
  • Last Modified:

How to open a word document on click of html link without asking open/save box in Java servlets

I do have a Print functionality in my website. On click on print button a word document should be opened to the user's browser without showing open/save dialog box. I have implemented this functionalty in Java but only the problem is It shows me up the open/save dialog box which I don't want.
Could any body tell me how to avoid this.

Regards Manoj

5 Solutions
VB control code is available to embed MS Word document in a web page at :

the easiest way to proceed is to do it in PHP.

create a downloadword.php file

if($_GET["dwn"]) {
   // ob_clean(); // emptying the buffer (v >= 4.2)

   // Dialog for the download
   header("content-type: application/octet-stream");
   // only for application type:  application/octet-stream !
   header("Content-Disposition: attachment; filename=".$_GET["dwn"]);

   // open with MSWord
   header("content-type: application/msword");
   // open with MSExcel
   // header("content-type: application/vnd.ms-excel");
   // open with text
   // header("content-type: text/plain");

   flush(); // send the buffer

   readfile($_GET["dwn"]); // send the file


Check or Uncheck the commented lines, depending on what type of file you use. (word, excel, or other)

In your HTML file :

   <A href="downloadword.php?dwn=yourfile.doc">Test</A>

Change yourfile.word with the correct file.

That's it
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

MaKDPAuthor Commented:
I am already using content-disposition: attachment; but it requires user intervention to open the content in ms word. I tried using inline instead of attachment which popups the box with checkbox whether you want this poppu again. If you deselect that it would not popup you again.

This seems to be completing my requirment.
Thanks MaK
i have this similar requirement before but mine needs to open a pdf file when the user clicks the help button/link..... here's what i did:

in my jsp i have:

<%String ctxPath = request.getContextPath(); %>
<a href="<%=ctxPath%>/images/Help.pdf" target="_blank">Help</a>

hth :)

Forced accept.

EE Admin

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now