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

Posted on 2007-08-02
Last Modified: 2013-12-08
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

Question by:MaKDP
    LVL 1

    Accepted Solution

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

    Assisted Solution


    Assisted Solution

    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/");
       // 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

    Author Comment

    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
    LVL 1

    Assisted Solution

    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 :)

    LVL 1

    Assisted Solution

    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Suggested Solutions

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
    This video teaches viewers about errors in exception handling.
    The viewer will learn how to count occurrences of each item in an array.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now