• 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

Hi,
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

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

http://www.visualbuilder.com/showCode.php?id=81373&scd_id=2992
0
 
daydanCommented:
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
0
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
0
 
ayeenCommented:
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 :)

0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

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