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

Similar Messages

  • After downloading my file the word document is mostly gibberish.  Why? service used exportPDF

    After downloading my file the word document is mostly gibberish.  Why? Service used "exportPDF".

    Hi shelbyrn,
    The quality of a conversion really depends on the quality of the original PDF file. Please see Will Adobe ExportPDF convert both text and form... | Adobe Community.  Do you know what or how the PDF file was created?
    You may have better luck by disabling OCR as described in this document: How to disable Optical Character Recognition (O... | Adobe Community. (Note, however, that is  option isn't optimal if the PDF was created from a scanned document; you'd want OCR enabled to convert the image text in the PDF to editable text).
    Best,
    Sara

  • Good day sir, please i just got an iPAD 4 and I have bee having a serious difficulties performing some operations on it of which  was told it is possible one of which is to create a microsoft word documents on my iPAD the second is attaching a file to y e

    Good day sir, please i just got an iPAD 4 and I have bee having a serious difficulties performing some operations on it of which  was told it is possible one of which is to create a microsoft word documents on my iPAD the second is attaching a file to y e mail in order too send Also, I have not been able to safe a download files on my iPAD as I do not have a download manager on it. Please, kindly send to me ways of getting these problems fixed as i am a young resarcher who sends a lot of mails and download as wel. Als, I am always on the move as this has propmted me in the first place to get an IPAD .
    Last but not the list II will equally wish to know if it will be possible for  me to use a pen to take seminar notes on my iPAD and safe the same on my iPAD fr later reference as it is done on other tablets ke samsung. I read somethng like stylus pen but I don't know how far. Please, kindly make an appropriate recommendaton for me and where i can get it. I reside in Turkey and currently a Ph.D stuudent in ine of the leading niversities in the country. Also, I will like to know if you ave ecoonomics text books that I can buy or published journas in apple store because i have searched but could not get  a desirerable ones.
    Once again, thanks for your anticipated prompt rely to my mail.
    Regards
    Wasu Fawole

    Have a look at the following:
    http://itunes.apple.com/sg/app/quickoffice-pro-hd-edit-office/id376212724?mt=8&l s=1
    http://itunes.apple.com/sg/app/office2-hd/id364361728?mt=8&ls=1
    http://itunes.apple.com/sg/app/documents-to-go-premium-office/id317107309?mt=8&l s=1
    http://itunes.apple.com/sg/app/polaris-office/id513188658?mt=8&ls=1

  • 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 downloaded Lion onto my Mac, and now cannot open or access any of my Microsoft word documents or Power Points. Is there a fix for this? I need my documents

    I downloaded Lion onto my Mac, and now cannot open or access any of my Microsoft word documents or Power Points. Is there a fix for this? I need my documents

    If it's because you were using Office 2004, the eight year old version of Office that was written when Intel processors were not used in Macs, then there will be no fix. Lion dropped support for PowerPC applications, as has been widely reported since Lion's release last August.
    You can upgrade Office 2004 to Office 2008 or Office 2011. You can use iWorks 2009 that can open Microsoft files. You can use a number of free applications that are also capable of working with Microsoft documents. You can go back to Snow Leopard, if you have a backup. Or, if you have an external drive or room to add a partition to your current drive, you can install Snow Leopard on it.
    Search these forums for more information. If this is your issue, it's been posted and answered several times a day since August 2011.

  • How can I convert my Open Source document files into Word document files? I cannot download Pages since my Macbook Air does not have the most recent software.

    How can I convert my Open Source document files into Word document files? I cannot download Pages since my Macbook Air does not have the most recent software. I downloaded open office to my mac to try and save money. It worked well for a while. Now I get this pop-up message that asks me to "Reopen" and when I select the option, nothing happens. I cannot save my documents anymore and I cannot convert them to word. Help!

    dwb wrote:
    Does OpenOffice output Word documents by default or do you have to select it manually?
    You have 17 options to save as in Open Office, one of which is .doc  files,  yes it needs to be saved manually.
    You may be able to default to DOC, but have not tried same.
    Since Open Office is 99% same as Word, I use it, or Word, either one.  Open Office is a bit less buggy than Word 11'

  • How can I change a Microsoft Word document file into a picture file?

    How can I change a Microsoft Word document file into a picture or jpeg file? I am wanting to make the image I created my background on my macbook pro.

    After I had the document image the way I wanted it, I saved it as a web page and went from there. Below are the steps starting after I did the "save as" option in Word:
    1) Select "Save As Web Page". I changed the location from documents to pictures when the window came up to save it as a web page.
    2) Go to "Finder" on you main screen, or if it's on your main toolbar at the bottom.
    3) Click on the "Pictures" tab and find the file you just re-saved as a web page. (I included "web page" or something similar in the new title so I could easily find the correct file I was looking for)
    4) Open the correct file and then "right click" on the actual image. (Use 2 fingers to do so on a Mac)
    5) Select 'Use Image As Desktop Picture", and voilà! The personally created image, or whatever it is that you wanted, is now your background.
    **One problem I encountered while doing this is that the image would show up like it was right-aligned in relation to the whole screen. The only way I could figure how to fix this was to go back to the very original document in Word, (the one before it was saved as a web page), and move everything over to the left.
    I hope this helps someone else who was as frustrated as I was with something that I thought would have been very simple to do! If you have any tips or suggestions of your own, please feel free to share. : )

  • CAN'T OPEN MICROSOFT WORD DOCUMENTS AFTER DOWNLOADING MAVERICK

    I downloaded Maverick OS X 10.9.3 and now I can't open my Microsoft Word documents!  HELP!!
    The message I receive when trying to open a document read:  You can't open the application "Microsoft Word" because PowerPC applications are no longer supported.
    I wish I knew this before I upgraded to Maverick.  It happened to my iphotos as well but after purchasing new software for iphoto, I have been able to retrieve my photos. 
    I hope I don't have to do the same for my documents.
    Thanks

    I wouldn't recommend buying the boxed version of Office 2011. A new version of Office is coming out in a few months and you'll be stuck with old software. The next version of Office will be subscription only. You can buy Office 365 now and it will automatically upgrade you for free when the new version comes out. This is a monthly fee.
    If paying monthly is not an option for you, you can also look at buying Office 2008. While it's End of Life software like Office 2004 (this means it will receive no further updates) it will run in Mavericks with only a few minor glitches. You might be able to buy Office 2008 at a more reasonable price. Otherwise I would like at LibreOffice or OpenOffice that Esquared mentioned above.

  • How do I maintain my hyperlinks when converting a Microsoft Word Document to a PDF file?

    How do I maintain my hyperlinks when converting a Microsoft Word document to a PDF file?

    Hi Marbarrose,
    When you make word file including hyperlinks then convert in pdf.
    It will automatically maintain hyperlinks.
    Regards,
    Florence

  • Convert 1 single microsoft word document with section breaks to multiple pdf files

    I am a windows 7 users. I have a single microsoft word document which contain 1500 pages. These 1500 pages are seperated by sections breaks in the microsoft word. I am trying to convert this word document to multiple pdf files seperated by the section breaks in the Microsoft word. How can I convert the single microsoft word document with section breaks to multiple seperate pdf files?

    Acrobat (Adobe PDF Printer and PDFMaker ) doesn't recognize the Section breaks.  It never has as far as I am aware.  The easiest thing to do is to manually break up a copy of the MS Word Document into the Sections you need and then create the PDFs from those MS Word documents.

  • HT2506 hi i can't seem to copy and paste pdf files from preview to a microsoft word document. it always comes up with nonsense characters in the word document. how do i fix this? thanks in advance

    hi i can't seem to copy and paste pdf files from preview to a microsoft word document. it always comes up with nonsense characters in the word document. how do i fix this? thanks in advance

    Hi,
    The quickest way to do this (tested with OS 10.8.2, MS Word 2011) is in one line:
    tell application "Microsoft Word" to close every document whose name begins with "book"
    The reason why your script doesn't work is that you aren't specifying to Word which document you want it to close.
    So, changing one line ought to do it:
    close document incrementvalue -- instead of "close document"
    But... when you close a document, you change the document count. Document 2 becomes document 1, document 3 becomes document 2 etc. So eventually you'd get a message saying "The object you are trying to access doesn't exist".
    Because of this, if you want to do it in a repeat loop, you have to work backwards:
    tell application "Microsoft Word"
      set doc_count to count documents
      repeat with x from doc_count to 1 by -1
      if name of document x begins with "book" then close document x
      end repeat
    end tell
    Hope this helps.

  • HT1444 If i download the new OS X Mountain Lion to my Macbook Pro that has Snow Leopard, will i lose my apps and downloads (such as: Microsoft word, powerpoint, excel, oovoo, skype) and will i lose all of my pictures/documents and information?

    If i download the new OS X Mountain Lion to my Macbook Pro that has Snow Leopard, will i lose my apps and downloads (such as: Microsoft word, powerpoint, excel, oovoo, skype) and will i lose all of my pictures/documents and information?

    I should just change the OS and leave all your apps and data alone.  That said, if any of your apps are old and use Rosetta (ppc apps), they won't run under Mountain Lion.
    Make sure you take a good Time Machine or Clone backup before you convert.
    You can check compatibility of your apps here:
    http://roaringapps.com/apps:table

  • How can I restore my Microsoft Word Documents which became Unix Executable Files after my Macbook Pro Crashed?

    After my MacBook Pro suddenly crashed, we had Best Buy's Geek Squad attempt to save the files. According to them, they were successful in doing so and put all of the saved files in a folder on my desktop which they labeled "Backup". The problem is, all of the files are in a Unix Executable format. When you double click on any of them, they pull up the terminal and that's it. After researching the issue and trying to grasp what was going on, I learned that you can open these files in Text Edit and sometimes find the file extension (.png .jpeg .amr .qt) that belongs at the end of the filename in order for it to be pulled up. In doing this, I had some success restoring some photos, audio files, and videos. However, no luck at all in restoring any of my Microsoft Word documents or even finding out which Unix Executables are Word documents. I've even tried to add .docx to various files just to see if I would luck out. Nope .  Any help would be SO SO greatly appreciated!!!

    Just to make sure, your Mac meets Snow Leopard's requirements?
    Mac OS X v10.6 Snow Leopard - Technical Specifications
    Yes, Lion does require that  you have Snow Leopard installed so you have access to the Mac App Store.
    And you do need to be running v10.6.8 in order to upgrade to Lion >  http://www.apple.com/macosx/how-to-buy/
    When you verified the startup disk using Disk Utility, what were the results?
    Wouldn't hurt to do that again. From your admin account launch Disk Utility. Select MacintoshHD in the panel on the left then select the First Aid tab. Click: Verify Disk  (not Verify Disk Permissions).
    If the startup disk needs repairing, boot from your install disk to make repairs >  Using Disk Utility to verify or repair disks
    While you have the DU window open, check Capacity & Available at the bottom of the window. Make sure there is a minimum of 15% free disk space.

  • Since I downloaded Lion I can no longer access my microsoft Word documents.  Is there anything I can do?

    Since I downloaded Lion in order to use iphone 4s & icloud, I can no longer open Microsoft Word documents. 

    You have Word/Office 2004 and that won't run on Lion. You have three options:
    1. Upgrade to Office 2008 or 2011
    2. Download the free Office suite Libreoffice
    3. Buy Apple's 'Pages' (for word processing) programs from the App store.

  • Microsoft Word document to PDF file

    When converting a saved Microsoft Word document into a PDF file, the image changes...... Figures that were saved in the original document are then either lost or hidden/partly obscured by other items.
    Any help greatly appreciated
    [email protected]

    Nigel,
    This questions belongs in the Acrobat forum. It is not a pdf
    specification issue. The short answer is that when you change printers
    Word reflows the document. Create the Word document with the Acrobat PDF
    printer instance as the default printer driver. That should take care of
    your problem. If it does not please repost your question in the Acrobat
    forum.
    Mike

Maybe you are looking for