Struts Action Downloads MS word Document

Hi
All
I�m trying download a MS word Document by action using the following java code:
ByteArrayOutputStream writerBytes = new ByteArrayOutputStream();
response.setContentType("application/word");
response.setHeader("Content-disposition", "inline; filename=" + "c:\\temp\\MyDocument.doc");
response.setContentLength(writerBytes.size());
ServletOutputStream writer = response.getOutputStream();
writerBytes.writeTo(writer);
writer.flush();
writer.close();
But it always open the MS word as a new file.
The correct is download and opens the file.
What is wrong with this code ?
Thanks

Eh, nay. M$ products aren't designed to be modified or
extended, Huh? Compared to what?
I doubt you can do it in the builtin VB, I suspect you can do it with Word Basic.
but definately not java.I agree with that. At the very least it would require using another language in addition to java.
You could also write a printer driver that just redirects the output.

Similar Messages

  • I am getting an unknown error when trying to download a word document from mail to pages, any help

    I am trying to download a word document from mail into pages and I keep getting an unknown error message, are there special settings for this? Any help much appreciated!

    Not there aren't any special settings for this. You just use the Open In feature to save the document into Pages. You could have a font in the document that Pages doesn't like, maybe something that you copied and pasted from somewhere into the document that went corrupt. But there is nothing special about the way that you save a Word document into Pages. You save it like you save any document or file into a compatible app.

  • When I download Microsoft word documents (if have word 2007), I have somehow changed the settings and it downloads them in wordpad, and the format is very bad and I can't read a lot of the document. How do I change the default setting back to using Micro

    When I download Microsoft word documents (if have word 2007), I have somehow changed the settings and it downloads them in wordpad, and the format is very bad and I can't read a lot of the document. How do I change the default setting back to using Microsoft Word 2007 to open these documents?
    == This happened ==
    Every time Firefox opened
    == about a few weeks ago - I had tried to open some docuuments saved on a mac, my PC (which runs Windows 7), used word pad to open these, and this seems to have changed the default settings somehow.

    See this:
    [http://support.mozilla.com/en-US/kb/Managing+file+types]

  • I cn't download saved word documents from icloud to my mac? Why?

    I use Word for Mac as my word processor. I'm a writer and publishers only want word .doc documents. I can upload to icloud but not download my word documents and icloud doesn't appear as a source for documents neither on the Pages nor the Word menu. why? and what can I do?

    At http://icloud.com , navigate to the iWork page,and click on the relevant folder in the toolbar:
    Click your file once to select it: click 'Download' and choose an option.
    More information at http://help.apple.com/icloud/#mm9d23dae8
    However, once a file has been uploaded from your Mac you cannot re-download it until it's been edited on an iOS device, which may well make this process unsuitable for your requirements. You may find DropBox a better bet.

  • Unable to download attached Word document

    I have two emails in my inbox with attached Word documents neither of which will download. I download documents all the time so am not doing anything wrong to get them to download. I have a Dell 1525 Inspiron running Vista. Mozilla is the browser
    == This happened ==
    Just once or twice
    == an hour ago

    My AOL emails won't print. This change occurred a few days ago when I did the last FireFox upgrade. The aspx extension appears to be the difference?

  • Trying to download a Word document

    I have uploaded a PDF, converted to Word and am now attempting to download it.
    In IE10 I get the usual popup dialogue (save, open, etc) but none of th eoptions work and I cannot even cancel the download popup.
    In Firefox and Chrome I get 'page not found' errors.
    How do I download my converted document!

    Hi jmsmith01
    Sorry for the inconvenience, can you please give a try using Adobe Reader? You can download free reader from this location: http://get.adobe.com/reader/
    ~Deepak

  • Struts Action Download File

    Hi
    All
    I�m downloading a word file by action using the following java code:
    ByteArrayOutputStream writerBytes = new ByteArrayOutputStream();
    response.setContentType("application/word");
    response.setHeader("Content-disposition", "inline; filename=" + "c:\\temp\\MyDocument.doc");
    response.setContentLength(writerBytes.size());
    ServletOutputStream writer = response.getOutputStream();
    writerBytes.writeTo(writer);
    writer.flush();
    writer.close();
    But it always open the MS word as open a new file.
    What is wrong with this code ?
    Thanks

    response.setHeader("Content-disposition", "inline; filename=" + "c:\\temp\\
    MyDocument.doc");
    It�s impossible How does the Action know the exactly the name to downalod?
    Thanks

  • How can i download my word documents from my macbook pro to my IPad?

    I have many documents on my macbook pro that are word documents i want to download to my new IPad. How can i do this. I have read there is a way to do it through ITunes, but i have no idea how to do that either?
    Help

    You can copy documents to the iPad, but first you need one or more apps on the iPad that supports the type of document that you want to copy - unlike a 'normal' computer the iPad doesn't have a file system, and everything on it has to be associated with an app.
    For word documents the options include Apple's Pages app, and from third-parties apps such as Documents To Go ('premium' version) and QuickOffice Pro HD.
    As to how you then get the file to your chosen app will depend upon what the app supports - different apps will have different ways of copying their content to/from a computer e.g. via the file sharing section at the bottom of the device's apps tab when connected to iTunes, via wifi, email, dropbox etc.

  • New macbook owner need insight on downloading a word document?

    I just got a new macbook for college.. never had one before and im use to hp with windows..now, is there a program like Microsoft Word i need to download?? to write word documents and stuff?

    Download?
    If you mean how to read/edit/use WORD documents on your Mac....your University should be able to sell you MS  Office, or you can buy/download from Amazon.
    You can also use NeoOffice (Google is your friend), or switch to Pages, the Apple solution.

  • Enable downloading of Word document

    I have a customer who wants a Word document added to web site
    with TIF logo embedded so that employees can download document and
    add copy to it for printing off their office printer.
    HELP!!!

    if you link to the .doc, anyone who has word installed will
    have the file
    opened in word automaticly. They can then do with it as they
    wish. If the
    user does not have word on there computer they will be
    prompted to choose an
    app to open it.
    IE ... just link to the .doc...don't worry about zipping it
    Jeff
    "dreamweeper" <[email protected]> wrote in
    message
    news:fggamh$6vm$[email protected]..
    >I have a customer who wants a Word document added to web
    site with TIF logo
    >embedded so that employees can download document and add
    copy to it for
    >printing off their office printer. HELP!!!

  • Reg : Download pdf,word documents

    Hi ,
    How to download the Pdf , word doc with data. Please give me clear idea.
    Thanks
    Risha

    Hi,
    What exactly do you need, do you need to dowmload the data of a table to an word file or an pdf?
    If that is the case why dont you downloasd the data into en excel file
    If you want to download the data into an excel refer the following blog
    /people/sap.user72/blog/2006/05/04/enhancing-tables-in-webdynpro-java-150-custom-built-table-utilities
    Thanks
    Jeet

  • Downloading of file(Microsoft Word Document)

    I have a problem regarding with downloading of Word Document file, the download is working but the when i open the file an was Exception written in the File, here is my code, can anybody help me with this problem? any help is greatly appreciated
    public ActionForward execute(ActionMapping mapping, ActionForm form,
                   HttpServletRequest request, HttpServletResponse response)
                   throws Exception {
              ActionErrors errors = new ActionErrors();
              ActionForward forward = new ActionForward(); // return value
              UtilityBean _bean = null;
              String fileName = "Sample.doc";
              System.out.println("Download Word Document");
              //               set the header details
              int id = 8;
              System.out.println("ID is: " + id);
              // details
              System.out.println("Download Word Document");
              // set the header details
              try {
                   _bean = new UtilityBean();
                   _bean = DAOFacade.file(id);
                   response.setContentType("application/msword");
                   response.setHeader("Content-Disposition", "attachment; filename="
                             + fileName);
                   //set the content type to related file
                   FileOutputStream fileOut = new FileOutputStream(
                             "c:\\tempWordOutput.doc");
                   InputStream inStream = new BufferedInputStream(new FileInputStream(
                             "c:\\tempWordOutput.doc"));
                   OutputStream outStream = response.getOutputStream();
                   // set buffer size. Each attempt to read the file will use // //
                   // specified number of bytes
                   byte[] buf = new byte[4 * 1024];
                   int bytesRead = 0;
                   while ((bytesRead = inStream.read(buf)) != -1) {
                        outStream.write(buf, 0, bytesRead);
                   outStream.flush();
                   outStream.close();
                   inStream.close();
              } catch (Exception e) {
                   e.printStackTrace();
              // If a message is required, save the specified key(s)
              // into the request for use by the <struts:errors> tag.
              if (!errors.isEmpty()) {
                   saveErrors(request, errors);
                   // Forward control to the appropriate 'failure' URI (change name as
                   // desired)
                   //     forward = mapping.findForward("failure");
              } else {
                   // Forward control to the appropriate 'success' URI (change name as
                   // desired)
                   // forward = mapping.findForward("success");
              // Finish with
              return (forward);
         * @return
         private HttpServletResponse HttpServletResponse() {
              // TODO Auto-generated method stub
              return null;
    //------------------------GENERATED FILE------------------------------------
    <H1>Error page exception</H1>
    <H4>The server cannot use the error page specified for your application to handle the Original Exception printed below. Please see the Error Page Exception below for a description of the problem with the specified error page.</H4>
    <BR><H3>Original Exception: </H3>
    <B>Error Message: </B><BR>
    <B>Error Code: </B>500<BR>
    <B>Target Servlet: </B>action<BR>
    <B>Error Stack: </B><BR>
    java.lang.NullPointerException
    <BR>    
         at org.apache.struts.action.RequestProcessor.processForwardConfig&#40;RequestProcessor.java:441&#41;
    <BR>    
         at org.apache.struts.action.RequestProcessor.process&#40;RequestProcessor.java:279&#41;
    <BR>    
         at org.apache.struts.action.ActionServlet.process&#40;ActionServlet.java:1482&#41;
    <BR>    
         at org.apache.struts.action.ActionServlet.doGet&#40;ActionServlet.java:507&#41;
    <BR>    
         at javax.servlet.http.HttpServlet.service&#40;HttpServlet.java:743&#41;
    <BR>    
         at javax.servlet.http.HttpServlet.service&#40;HttpServlet.java:856&#41;
    <BR>    
         at com.ibm.ws.webcontainer.servlet.ServletWrapper.service&#40;ServletWrapper.java:1212&#41;
    <BR>    
         at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest&#40;ServletWrapper.java:629&#41;
    <BR>    
         at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest&#40;WebApp.java:2837&#41;
    <BR>    
         at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest&#40;WebGroup.java:220&#41;
    <BR>    
         at com.ibm.ws.webcontainer.VirtualHost.handleRequest&#40;VirtualHost.java:204&#41;
    <BR>    
         at com.ibm.ws.webcontainer.WebContainer.handleRequest&#40;WebContainer.java:1681&#41;
    <BR>    
         at com.ibm.ws.webcontainer.channel.WCChannelLink.ready&#40;WCChannelLink.java:77&#41;
    <BR>    
         at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination&#40;HttpInboundLink.java:421&#41;
    <BR>    
         at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation&#40;HttpInboundLink.java:367&#41;
    <BR>    
         at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete&#40;HttpICLReadCallback.java:94&#41;
    <BR>    
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete&#40;WorkQueueManager.java:548&#41;
    <BR>    
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO&#40;WorkQueueManager.java:601&#41;
    <BR>    
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun&#40;WorkQueueManager.java:934&#41;
    <BR>    
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run&#40;WorkQueueManager.java:1021&#41;
    <BR>    
         at com.ibm.ws.util.ThreadPool$Worker.run&#40;ThreadPool.java:1332&#41;
    <BR>    
    <BR>
    <BR><BR><H3>Error Page Exception: </H3>
    <B>Error Message: </B>SRVE0199E: OutputStream already obtained<BR>
    <B>Error Code: </B>0<BR>
    <B>Target Servlet: </B>null<BR>
    <B>Error Stack: </B><BR>
    java.lang.IllegalStateException: SRVE0199E: OutputStream already obtained
    <BR>    
         at com.ibm.ws.webcontainer.srt.SRTServletResponse.getWriter&#40;SRTServletResponse.java:462&#41;
    <BR>    
         at com.ibm.ws.webcontainer.webapp.WebApp.sendError&#40;WebApp.java:2484&#41;
    <BR>    
         at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest&#40;WebApp.java:2861&#41;
    <BR>    
         at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest&#40;WebGroup.java:220&#41;
    <BR>    
         at com.ibm.ws.webcontainer.VirtualHost.handleRequest&#40;VirtualHost.java:204&#41;
    <BR>    
         at com.ibm.ws.webcontainer.WebContainer.handleRequest&#40;WebContainer.java:1681&#41;
    <BR>    
         at com.ibm.ws.webcontainer.channel.WCChannelLink.ready&#40;WCChannelLink.java:77&#41;
    <BR>    
         at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination&#40;HttpInboundLink.java:421&#41;
    <BR>    
         at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation&#40;HttpInboundLink.java:367&#41;
    <BR>    
         at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete&#40;HttpICLReadCallback.java:94&#41;
    <BR>    
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete&#40;WorkQueueManager.java:548&#41;
    <BR>    
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO&#40;WorkQueueManager.java:601&#41;
    <BR>    
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun&#40;WorkQueueManager.java:934&#41;
    <BR>    
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run&#40;WorkQueueManager.java:1021&#41;
    <BR>    
         at com.ibm.ws.util.ThreadPool$Worker.run&#40;ThreadPool.java:1332&#41;
    <BR>    
    <BR>

    <B>Error Message: </B>SRVE0199E: OutputStream already obtained<BR>
    <B>Error Code: </B>0<BR>
    <B>Target Servlet: </B>null<BR>
    <B>Error Stack: </B><BR>
    java.lang.IllegalStateException: SRVE0199E: OutputStream already obtained
    this is the error because you have alredy closed the output stream
    outStream.flush();
    outStream.close();
    and then you return the Actionforward and struts Controller tries to write to the already closed output stream once again and hence the above exception is thrown
    Please refer to the below link to find how to implement a download action in struts
    http://wiki.apache.org/struts/StrutsFileDownload

  • Opening Word documents with Appleworks

    I often receive Word documents as email attachments (though my hotmail account). I can download these Word documents to my desktop but when I click on them to open them I get an offer to purchase MS Word (which I do not have). I would like to be able to simply open the Word documents with Apple works--and I am hoping I can just click on them and have that happen automatically. But it doesn't. I have tried opening Appleworks and going into the wordprocessing program and then opening the Word document through that, but it only is successful part of the time. What can I do? I would like to have these Word douments open automatically in Appleworks but every time I click on them (i.e., their icon on my desktop) I get that advertisement from Microsoft asking me to buy Word. Is this ad blocking a normal function of Appleworks that would otherwise allow me to open Word documents with a click? And in any case, how can I proceed?

    The ad for Word is almost certainly being tacked on through or at Hotmail (taglines or adware from Hotmail? Hoodathunk .....) ; it sure isn't coming from AppleWorks or from anything on your own system, unless you have that demo copy of Office still lurking somewhere. I suppose it could come from that, somehow.
    Assuming you can get a clean attachment downloaded to your Desktop from Hotmail, the procedure for having what you want to happen automatically is fairly straightforward and, really, has nothing at all to do with Appleworks. Try the following:
    --> Select (highlight) one of those downloaded .doc files from Word, then
    --> use the Finder's Get Info command (⌘-I). In the window which appears,
    --> see the "Open with" section, and set it to AppleWorks.

  • Document Library - Workflow not starting on copied Word Document

    HELLO EVERYBODY!
    Right, got a weird issue on a Document Library, where if the Document Library already contains a Word Document with a Title of 'Document 1' and i download the document, make a change and re-upload it. The document uploads as a new separate file but it retains
    the same 'Document 1' title.
    My problem is that for some reason SharePoint isn't seeing this newly uploaded document and therefore it is not running the workflow on it?
    This really confuses me, as it will work with new documents, but it will not work if you download a Word document, change it and re-upload the document as a new version, the workflow will not start.
    Any ideas are welcome.
    Thanks,
    Tucker

    Hi Tucker,
    According to your description, my understanding is that the workflow which was set to start when an item is created cannot start when uploading a copy of a document existing in the library.
    I tested the same scenario per your post, and the workflow can start automatically.
    As the workflow can start automatically when uploading a new document, it is not the issue with the workflow.
    I recommend to verify the things below:
    Did you upload the copy with a new name as a separate file or as a new version to the existing document to the library?
    Test with a new library and a new document to narrow the issue scope.
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • Email Word documents to be stored on iWork for iCloud

    Is it possoible to email Word documents to be stored on iWork for iCloud?

    Yes. One way is to download the Word documents and drop them into your Pages for iCloud window (the one where all your files are shown and not a blank word processing page).

Maybe you are looking for

  • How do i get my ipod to recognize my new computer

    How do I get my ipod to recognize/sync with my new computer?

  • REGD-PAYMENT TERMS

    Hi Experts, I tried to create a purchase order on 31.01.2007 with payment term ‘ZB11’, but I couldn’t and I got the following error “Error in net price calculation” as February is having 28 days. The problem only exists one day in a year i.e. on 31.0

  • TS2446 will i get notification when i sign in to icloud on a new computer

    will i get notification when i sign in to icloud on a new computer

  • Help-can't open file???

    have a filed saved in imovie, but when try and open it, its just says cannot open this file. When I look at it in finder, all the parts seem to be there! is there anyway I can open it which exporting all the clips? I have made a piece of music in it,

  • Cross platform installation

    I need to download Digital Editions for Pocket PC ( Windows Mobile 2003 second ed.), but at the moment I can only connect my Mac Powerbook to the net. I then plan to transfer it to my PDA. I have installed Digital Editions on the powerbook and it wor