Download a .doc file from a servlet, problems with filters

          Hi! I put this post in an incorrect forum so I think this is the correct one. Hope
          anyone can help.
          We need some help in order to view a .doc file that we've stored into a blob column
          of some oracle table. The file is compressed using Zip classes and now what we
          want to do is:
          We have a web page with a link to a servlet that will read the blob, unzip the
          file and show it into a new web page with ms word.
          The problem appeared when we put some compression filters in our WL 6.1 SP3 and
          the result is always the same. When we tell IExplorer to save the file it works
          correctly but when we tell him to open the document it shows the "Open with..."
          window as if the content-type or any other header was incorrect.
          Here is part of the code:
          ....... if(mydoc!=null && mydoc.length>0){ res.setHeader("Content-Type", "application/msword");
          res.setHeader("Cache-Control","no-cache"); res.setHeader("Content-Disposition",
          "attachment;filename=\"mydoc.doc\"" ); if(isZIPPED == 1){ ByteArrayInputStream
          array = new ByteArrayInputStream(informe); ZipInputStream zip = new ZipInputStream(new
          BufferedInputStream(array)); ZipEntry entry; while((entry = zip.getNextEntry())
          != null){ int n; byte mydata[] = new byte[16384]; ServletOutputStream out = res.getOutputStream();
          while((n = zip.read(mydata, 0, 16384)) != -1){ out.write(mydata, 0, n); } } }
          ... So, what are we doing wrong?
          Any help will be much appreciated!! Thanks.
          

problem dissapeared, no need anymore to solve this one.

Similar Messages

  • PROBLEM while using URL in order to open a file from a servlet

    Hi,
    I am having a problem while trying to open a file from my servlet by using URL connection. Following is my code sample. what happens is when I first run my project it opens the file but after that when I rerun it again and again it sometimes opens it and sometimes not. if it can't open it it gives an error saying "the file is damaged and couldn't be repaired". I don't get any exceptions. if you guys can help me I will appreciate it so much... thanks.
    here is my code :
    URL url = new URL("http://demobcs.ibm.com:81/test.pdf");
    resp.setContentType(getContentType("http://demobcs.ibm.com:81/test.pdf"));
              ServletOutputStream sos = null;
              BufferedInputStream bis = null;
              try {
                   sos = resp.getOutputStream();
              } catch (Exception e) {
                   System.out.println("exception !!!!");
                   e.printStackTrace();
              System.out.println("burada2");
              try {
                   byte[] bytes = new byte[4096];
                   //bis = new BufferedInputStream(conn.getInputStream());
                   DataInputStream in = new DataInputStream(url.openStream());
                   //DataInputStream in = new DataInputStream(conn.getInputStream());
                   bis = new BufferedInputStream(in);
                   int j;
                   while ((j = bis.read(bytes, 0, 4096)) != -1) {
                        try {
                             sos.write(bytes, 0, 4096);
                             System.out.println("file is being read ...:");
                        } catch (Exception e) {
                             e.printStackTrace();
                   in.close();
                   bis.close();          
                   //sos.close();
              } catch (Exception e) {
                   System.out.println("exception :"+e.toString());
                   e.printStackTrace();
              }

    You are writing (<filesize> mod 4096) bytes of crap at the end of the file. Use your variable j instead for the number of bytes to write in your loop.

  • HT2488 How do I create a workflow in Automator or a script in AppleScripts to download an excel file from a specific webpage?

    I would like to create a workflow in Automator or a script in AppleScript (or a combination of the two), that opens Safari to a specified page and downloads an excel file from this page and saves the downloaded document to my desktop.
    Is this something that be done? If so, how?
    I have so far been able to build a workflow in Automator to open Safari and added an AppleScript that takes Safari to a specific page that has an Excel document.
    I can't figure out where to go from here... Any help would be apprecitated.
    Thanks!

    Would you have the web address the excel sheet is on?
    Is there a simular web page you could point to if not?
    Would there be a copy of the file on an FTP page.  This would be easier. 
    curl
    http://www.cyberciti.biz/faq/mac-os-x-terminal-download-file/
    http://www.thegeekstuff.com/2012/04/curl-examples/
    http://curl.haxx.se/docs/manpage.html
    Macintosh-HD -> Applications -> Utilities -> Terminal
    # Press return to run a command.
    the curl is a terminal command ( Unix ).  It allows you to read a file off of the web.
    man curl
    provides cryptic information on the commnad curl.
    press the space bar to advance  a page.
    press letter to q to quit.
    What you may have to is to read in the web page as a text file.  Go "fishing" through the page to find the excel file you need.  Once you find the file, you can use curl to read the file.
    curl is a very full featured command.  (read complex to figure out ).
    It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.
        Author: rccharles
        For testing, run in the Script Editor.
          1) Click on the Event Log tab to see the output from the log statement
          2) Click on Run
        For running shell commands see:
        http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html
    on run
        -- Write a message into the event log.
        log "  --- Starting on " & ((current date) as string) & " --- "
        --  debug lines
        set desktopPath to (path to desktop) as string
        log "desktopPath = " & desktopPath
        set unixDesktopPath to POSIX path of desktopPath
        log "unixDesktopPath = " & unixDesktopPath
        set quotedUnixDesktopPath to quoted form of unixDesktopPath
        log "quoted form is " & quotedUnixDesktopPath
        try
            set fromUnix to do shell script "ls -l  " & quotedUnixDesktopPath
            display dialog "ls -l of " & quotedUnixDesktopPath & return & fromUnix
        on error errMsg
            log "ls -l error..." & errMsg
        end try
    end run

  • I downloaded an Adobe file from my email but cannot find it on my hard drive or in recycle bin - it's in downloads but am unable to open from downloads - how can I recover the file?

    I downloaded an Adobe file from my email (service provider is MWeb) but now cannot find it on my hard drive and it's not in the recycle bin. It does, however, appear in Firefox downloads but I'm unable to open it from there. How can I recover the file?

    Thanks Rob.
    I actually had no clue what the core problem was caused by. So it's Windows itself...that helps some.
    I'll resubmit there. It might actually have saved time for it to simply have been moved to there instead of off-topic, though I suppose you have to follow protocol.

  • I am unable to accept a .doc file from a sender

    FILE TRANSFER ERROR:
    Could not receive file “FAIR v. Rumsfeld.doc” from Tiggsfrnpooh26:
    An error occurred.
    This is what comes up when i try to recieve it.
    I have had no trouble with sending and recieving files in the past, though this is the first time I have tried to recieve a .doc file from someone. And that someone is using a PC.
    Others I ahve recieved and sent files to with no problem were on macs, but i dont think that is the issue here.
    I do have port 5190 open as usual.
    Am i Missing something,
    any questions will be answered right away.

    Hi
    The " v. " was the thing causing the problem.
    12:23 PM Wednesday; March 29, 2006

  • Download a text file from JSP (Urgent Please!)

    Hi,
    I have a issue with this JSP, I need to download a txt file from my webserver to the pc client, the page shows the dialg box but appear the filename (list.jsp) of my jsp instead of the txt file.
    If I click the save buton save the list.jsp page; if I click in the open buton, then appear again the dialg box and now appear the url (download.jsp?filename=...) and if I click in the save button now I can save my txt file in the local pc.!!!!
    Any ideas ??
    list.jsp --> is the jsp from the download.jsp is run.
    download.jsp
    <%@ page import="java.io.*,javax.servlet.*,java.util.* "%><% String filename = request.getParameter("filename");
    response.setContentType("application/download");
    String value = "attachment; filename=\"" + filename + "\";" ;
    response.setHeader("Content-Disposition",value);
    int iRead;
    FileInputStream stream = null;
    try {
    File f = new File("C://test//" + filename);
    stream = new FileInputStream(f);
    while ((iRead = stream.read()) != -1) {
    out.write(iRead);
    out.flush();
    finally {
    if (stream != null) {
    stream.close();
    %>

    Maybe try no quotes around the content disposition header?
    Also, I'm not sure that application/download would be the best content type, maybe "application/octet-stream" instead. You should also probably explicitly set the Content-Length header to the file size.

  • HT3678 If I download a .mov file from gmail, I am not able to open the file. I reinstalled QuickTime 7.6.6, still unable to open the file. If I download the same file from another mail server I have no trouble. What is gmail doing to my file?

    If I download a .mov file from gmail, I am not able to open the file. I reinstalled QuickTime 7.6.6, still unable to open the file. If I download the same file from another mail server I have no trouble. What is gmail doing to my file?

    Also i have reinstalled the reader9 two  times and tried with reader8 also but in both the cases same problem.
    it would be gr8 help if someone can help.

  • How to send doc files from one system to another using XI

    Hi All,
    I have a requirement to pick the word doc files from one file system and send these word document files to ECC system place in ECC application server.Can we achieve this requirement using XI. If so how we can do this. also let me know can we convert these doc files into proxy and send to ECC?. Please let me know. Thanks.
    Regards,
    Rajesh

    Yes You Can
    XI Converts Unstructured data(That is non -XML)Type- in your case word doc and maps it to Target structure.
    You can either use content conversion
    /people/venkat.donela/blog/2005/03/02/introduction-to-simplefile-xi-filescenario-and-complete-walk-through-for-starterspart1
    /people/venkat.donela/blog/2005/03/03/introduction-to-simple-file-xi-filescenario-and-complete-walk-through-for-starterspart2
    /people/venkat.donela/blog/2005/06/08/how-to-send-a-flat-file-with-various-field-lengths-and-variable-substructures-to-xi-30
    /people/anish.abraham2/blog/2005/06/08/content-conversion-patternrandom-content-in-input-file
    /people/shabarish.vijayakumar/blog/2005/08/17/nab-the-tab-file-adapter
    /people/jeyakumar.muthu2/blog/2005/11/29/file-content-conversion-for-unequal-number-of-columns
    /people/shabarish.vijayakumar/blog/2006/02/27/content-conversion-the-key-field-problem
    /people/michal.krawczyk2/blog/2004/12/15/how-to-send-a-flat-file-with-fixed-lengths-to-xi-30-using-a-central-file-adapter
    You can either built a adaptermodule for the same(U nedd to have Some Java knowledge)
    You can also convert without creating any objects in integration directory link for the same is
    /people/william.li/blog/2006/09/08/how-to-send-any-data-even-binary-through-xi-without-using-the-integration-repository
    ***********Please Reward Points If find Helpful*********

  • Using a thread to write a file from a servlet

    Does anyone have some code that can help out my problem:
    I am writing a file from a servlet, but the servlet completes and loads another page prior to the file writing to disk being completed.
    I have tried using threads to stop the serlvet until the file has been completely written, but I am not experianced using threads properly, and so far have been unsuccesssful.
    I would sure appreciate some/any code to reference to overcome this problem.
    Thanks to any responses.
    Dale

    Hi the best idea for you is not to use thread, so that the file processing gets completed before your servlet start doing anything else..
    something like this.
    public void doGet(     HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
    System.out.println("Called Repo");     
    BufferedInputStream res = new BufferedInputStream((request.getInputStream()));
         File f= new File("img.jpeg");
         FileOutputStream fo = new FileOutputStream(f);     
              byte b[]=new byte[64];
              int line=res.read(b);
    while(line!=-1)
         fo.write(b);
         line=res.read(b);
    fo.close();
    //your remaining processing from here...
    regards

  • Hi i am trying to download a .xls file from server but i cant

    I am using Tomcat 5.0, Where i am trying to download a .xls file.. which was uploaded by me.. when i try to download the file using line.. the content of the jsp file is there in the .xls file, i cant get the original .xls file
    here my code.. i am request this page by a button click...
    browser ask me to save download.jsp file....
    how to download a .xls file from the server... the file was uploaded by me to a folder temp
    <%@ page
    contentType="application/vnd.msexcel; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"
    %>
    <jsp:include page="http://localhost:9999/temp/B.xls"/>

    Help me please, I have this:
    File ficheroXLS = new File(strPathXLS);
    FacesContext ctx = FacesContext.getCurrentInstance();
    if (!ctx.getResponseComplete()) {
    String fileName = ficheroXLS.getName();
    String contentType = "application/vnd.msexcel";
    HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
    response.setContentType(contentType);
    response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
    ServletOutputStream out = response.getOutputStream();
    out.write({color:#ff0000}ficheroXLS.toString().getBytes(){color});
    out.flush();
    out.close();
    ctx.responseComplete();
    My
    problem is marked with red color, I have a file. XLS and I want to
    download it, but to put what this red just showed me the PATH ...
    How can I do to make the contents of this file?
    What type of object must be the xlsReport?
    thanks greetings

  • How will I save the downloaded documents or files from my gmail account?

    How will I save the downloaded documents or files from my gmail account?

    http://forums.adobe.com/docs/DOC-2532

  • I downloaded a word file from an inbox mail (the mail app) onto my iPad2, where is this file stored? How can I delete it if it takes up space in my iPad? Any ideas??

    I downloaded a word file from an inbox mail (the mail app) onto my iPad, where is this file stored? How can I delete it if it takes up space in my iPad? Any ideas??

    Did you ever figure out what happened?
    I had the same experience as you did, but in my case it was a big fat pdf that Mail insisted I had to download before I could view it. As happened with you, I saw the file actually downloading, and after a time I was able to view the pdf. It's been my assumption that the pdf is still somewhere on my iPad, but I have no idea where, nor how to delete it if it is still there.
    Thanks.

  • How to download a .pdf file from a JavaMail application?

    hi to all,
    iam unable to download a .pdf file from a mailserver using
    my javamail application.i have downloaded all kind of files except .pdf.
    my code snipnet:
    public static void dumpPart(Part p) throws Exception {
    //     if (p instanceof Message)          dumpEnvelope((Message)p);
              System.out.println("CONTENT-TYPE: " + p.getContentType());
              Object o = p.getContent();
              if (o instanceof String) {
                   System.out.println("This is a String");
                   System.out.println((String)o);
                   } else if (o instanceof Multipart) {
                        System.out.println("This is a Multipart");
                        Multipart mp = (Multipart)o;
                        int count = mp.getCount();
    System.out.println("****************************************");
    System.out.println("count" + count);
    System.out.println("****************************************");
                        for (int i = 0; i < count; i++){
                             System.out.println("CONTENT-TYPE: " + p.getContentType());
                             dumpPart(mp.getBodyPart(i));
                        } else if (o instanceof InputStream) {
                             System.out.println("This is just an input stream");
                             InputStream is = (InputStream)o;
                             String filename=System.currentTimeMillis()+".exe     ";
                             FileOutputStream fos=new FileOutputStream(filename);
                             int c;
                             while ((c = is.read()) != -1)
                                  //System.out.write(c);
                                  fos.write((char)c);
    }//dumpPart
    what's wrong with this code?
    Nagaraju.G

    fos.write((char)c);Converting the byte to a char is unnecessary and probably harmful. Just do this: fos.write(c);

  • How to download a pdf file from the server from an strut application?

    Hi,
    I wan to download a pdf file from the server side to local system. Please help me how i use the down load option.

    Read up on the Struts download action [1].
    And next time, please post in the relevant forum, one of the web-tier ones [2].
    [1] http://wiki.apache.org/struts/StrutsFileDownload
    [2] http://forum.java.sun.com/category.jspa?categoryID=20
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    ----------------------------------------------------------------

  • Downloading an XML file from Website through BPEL/ADAPTER

    Hi,
    I want to download an xml file from one webpage through BPEL. I am using jdeveloper 10.1.3.3 to create a BPEL process and Adapters.
    Is there anyway to download the xml file from the site through FUSION middleware.

    what do you mean download, is it a site where you click a hyperlink then down load the file.
    This is not possible as this is invoked by human intervention. SOA suite is invoked by events. If you want to perform this kind of function you would need to create a jave service to perform this.
    Is there any posibility that there is a FTP link that you could use?
    cheers
    James

Maybe you are looking for

  • More Quantity of Raw Material noticed in Quality Inspection

    Dear Experts, We have done GR against the PO for a material. But in Quality Inspection, we have noticed that there is excess quantity of stock received which is more than the inspection lot quantity. My issue is that inspection lot quantity will be c

  • Flash causing crash

    Hi, Whenever I try to goto a website that plays flash, Safari will crash. I think it has something to do with me checking the box "open using Rosetta" which I need every now and then as 1 particular website only works under Rosetta (sheetmusicdirect.

  • Is it possible to preview images in the files panel?

    sorry in advance for what probably is a dumb question with a simple solution. i realize i can preview images in the assets panel-- but is it possible to preview image files while in the files panel instead? i have a lot of images organized within fol

  • CS3 and CS4 on same comuter

    Hello all, I have CS3 production premium suite on my laptop.  I upgraded to CS4 production premium suite.  I have to keep CS3 on my computer befause I have certain plug ins for Premiere that won't work in Premiere CS4 (cineform prospect hd and Procod

  • [SOLVED] D-bus not working (I guess)

    Hello I got a problem when it comes to D-bus. Neither pulseaudio nor network-manager-applet is working for me due to this error that comes up: W:[pulseaudio] main.c This program is not intended to be run as root (unless --system is specified). E: [pu