Servlet not streaming PDF to browser properly

Hello,
I have a servlet that is processing file uploads and streams the file upload to a browser. All works fine, except that for some reason the browser has it's own mind as to whether or not to load the PDF plugin. Word, excel, text, these files are 100% reliable. However, PDFs sometimes display, other times I get nothing in the browser window. No errors are logged in JBOSS/Apache. Here's a look at my code:
package com.iw.web;
import java.io.*;
import java.util.*;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.commons.fileupload.*;
public class FilePreview extends HttpServlet {
     public FilePreview() {
          super();
     public void destroy() {
          super.destroy(); // Just puts "destroy" string in log
          // Put your code here
     public void doPost(HttpServletRequest request, HttpServletResponse response)
               throws ServletException, IOException {
          boolean isMultipart = FileUpload.isMultipartContent(request);
          DiskFileUpload fu = null;
          fu = new DiskFileUpload();
          if(isMultipart)
               try
                    List fileItems = fu.parseRequest(request);
                    Iterator it = fileItems.iterator();
               while(it.hasNext())
                    //org.apache.commons.fileupload.
                    FileItem fi = (FileItem)it.next();
                    if (!fi.isFormField())
                         String contentType = fi.getContentType();
                    byte[] data = fi.get();
                         File file = new File(fi.getName());
                         response.setHeader("Content-disposition","filename=" + file.getName());
                    response.setContentType( contentType );
                    response.setContentLength(data.length);
                         //PrintWriter outStream = response.getWriter();
                         //outStream.println(file.getName() );     
                    ServletOutputStream sos = response.getOutputStream();
                    sos.write(data);
                    sos.close();
               catch(Exception e)
     public void init() throws ServletException {
          // Put your code here

UPDATE: I have finally figured out my problem and it has nothing to do with the servlet at all. What is in fact happening is that I have jboss running along side IIS and IIS forwards requests to JBOSS/Tomcat. For some reason the connector stops sending the file to tomcat, I suspect based upon file size or timeout something like that. Maybe a timeout config type thing that could be changed in the worker properties?

Similar Messages

  • Adobe Reader will not open PDF in browser simple answer.

    I just had this problem and was able to work through it with the help of tech support from TD Ameritrade.  The fix is simple so read on.  After uninstalling and reinstalling all things adobe and trying other recommendations on these forums I was stumped.  I called my broker tech section since I couldn't open their reports and we identified what my specific problem was.  For me, and I imagine some of you this will help and prevent a lot of wasted time.
    Nothing was wrong with my Adobe Reader.  My problem was that I have a 64 bit operating system and both of my default browsers were 64 bit browsers.  I did not know my internet explorer default browser was the 64 bit one until the technician that assisted me informed me that a recent windows update made all 64 bit systems default to 64 bit internet explorer browsers.  You cannot change that default by choosing between 64 bit and 32 bit, because you can only choose internet explorer.  That explains why my attempts to open with a 32 bit browsers always failed.  I also tried with Firefox thinking it was 32 bit and it failed as well.  The technician informed me Firefox is a 64 bit browser and then it made sense.  I guess the recent Adobe reader update caused a change that no longer allowed my 64 bit system and 64 bit browser to open PDF's through the browser. The technician who assisted me has a 64 bit system and only uses 64 bit browsers and can still open PDF's through those browsers.  That confused us for a while until we realized he had his Adobe updater turned off and therefore had not been exposed yet to the update that originated my problems.
    ****ANSWER FOR MY PROBLEM*******The quick answer is use Google Chrome or some other 32 bit browser.  If you set a 32 bit browser as your default, the PDF's will open.  You cannot set Internet Explorer 32 bit browser as your default if you have a 64 bit system and also have 64 bit Internet Explorer.  The windows update prevents you from doing it.  At least that is my understanding. 
    The bottom line is I have the newest Adobe Reader on a 64 bit system and can open any web PDF with Google Chrome set as my default browser, because it is a 32 bit browser.  The new Adobe Reader will not open PDF's with a 64 bit browser in Vista.  A 64 bit system is fine as long as you use the 32 bit browser to open your PDF's in Vista.  I hope this helps some avoid some headaches.  I wish it had been posted when my problem first arose. 
    I think you can use a 64 bit browser in Windows 9 or later, but for Vista the above applies.

    Yes I can create a short cut to internet exp. 32 bit on my desktop and I can even be using Internet expl. 32 bit, but when I try to open a PDF with adobe reader it won't work with internet exp. as my default browser b/c windows will always choose Internet exp. 64 bit which isn't supported yet by adobe reader.  With google chrome as my default browser windows can't choose an unsupported 64 bit browser in its place b/c google chrome doesn't have a 64 bit version.
    My post was for those people who may not have realized yet that windows would not ever choose Internet expl. 32 bit over Internet expl. 64 bit if both exist on their system.  For them it is easiest to just choose a default browser that only has a 32 bit version. 
    If I understood your reply correctly, you were telling me how to create a shortcut to Internet exp. 32 bit on my desk top.  However, having that shortcut on my desk top and opening my browser through it will not prevent the problem of windows choosing my Internet exp. 64 bit browser for pdf's I try to open from the web.  Thank you for your response, but I think the problem that I have tried to explain does exist for many users and can only be fixed by using a 32 bit browser that is not Internet explorer as your default browser.  At some point if windows fixes the update that always chooses Internet expl. 64 bit over Internet expl. 32 bit, then this will all be irrelevant.
    Thanks
    Sent from my iPod

  • Will not display pdf in browser window -

    will not display downloaded acrobat files from the web in browser window - safari -
    can save same download and view in acrobat and/or preview.

    Apple Safari 5.1 and Adobe Reader/Acrobat Advisory
    If you are running Lion v10.7 >  Known Issues | Adobe products on Mac OS 10.7 Lion

  • My latest download images will not show in my browser properly

    I am using Elements 5. I have 1100 images in the organiser.
    The only way I can see recent images is in the largest thumbnail view.
    If I reduce the size of the thumbnails, the images appear just as a blank square with the "eggtimer" icon.
    How do I correct this please?

    It seems either you have imported lot of photographs or your machine has low mermory.
    It usually happens when Organizer is working on thumbnail generation for lot many files. If you want to get rid of this, do 'Update Thumbnails' for photographs in group of 5-10 whichever works for you.
    try and share the results

  • Problem with opening pdf in browser

    Hello
    Acrobat X Pro 10.0.0.396 was installed on PC with Adobe Reader 9 (tried with Reader 10). When I open pdf documents from browser IE 8 or FireFox 3.5 i cann't see Tools panel and buttons from quick area (only Comments and Share).
    plugin in browser - Adobe Acrobat 10.0.0.396 but i think document opens with plugin from Reader. But i deleted it from PC
    thank you in advance

    Each user would have to set each browser individually.
    Note: I don't think it's possible to set the default PDF viewer with code for every user who visits the site.
    See the following link to enable Adobe Reader as the default PDF viewer in different browsers:
    http://helpx.adobe.com/acrobat/using/display-pdf-browser-acrobat-xi.html
    Note: Not all PDF viewer browser plug-ins support PDF submissions, and most 3rd party viewers may not support forms created with LiveCycle or forms with Extended Reader Rights enabled.

  • Flash not working with any browser after update

    After an update, flash videos will not stream in any browser (Chrome, Firefox, Safari). I did a clean install of flash and the browsers, but to no avail. Mac 10.10.2. Has anyone else experienced this?

    Sadly doing that did not fix my problem either.     I just tried doing that and uninstalling flash player, rebooting and then reinstalling flash and I am still having the same problem as I stated here.   http://forums.adobe.com/message/4014843#4014843
    I have checked that flash is enabled
    Unchecked hardware accerleration
    Set in the internet options to use software rendering
    Tried updating my drivers (it tells me my drivers are up to date, in any case I have only had this laptop since July)
    I even tried deleting cookies, though I use IE9 instead of firefox so I just deleted them all instead of just the one for youtube, I honestly can not find the folder for cookies anyway with this windows 7 and how it is set up to try and delete the one cookie.
    I am really at a loss as to what to do.

  • PDF in-browser will not show attachments panel

    Hi. I'm working with a PDF with attachments. I created it to open with the attachments panel visibile. It works fine except for in Chrome, it shows the PDF in-browser but the attachments panel is not visible. This is causing some problems for our site users.
    What is the solution here. I'm working my IT department to update the .htaccess file to force all PDF files to download, but this seems like an overly complex solution.
    Why won't the attachment panel just show up in Chrome?
    Thanks in advance (if this is not the right forum to ask this, any help would be appreciated)

    That's not exactly helpful, I know I can set my local computer settings . I was looking for a solution to force the download on our users pages. I came up with a solution regardless.
    I just ended updating the .htaccess, adding this command which forces all .pdf files to download versus rendering in the browser, however this is still ignored by Chrome:
    AddType application/octet-stream .pdf
    But since Chrome accepts HTML5, I also added the download attribute:
    <a href="../files/is/2013_EPP_RFP.pdf" download="2013_EPP_RFP.pdf" target="_blank">2013 EPP RFP</a></div>

  • Netbeans Issue: Servlet do not display Chinese UTF-8 properly

    Netbeans Issue: Servlet do not display Chinese UTF-8 properly
    Java Version: JDK1.5.0_01, JRE1.5.0_01 (International version)
    Netbeans Version: Netbeans IDE 4.0
    OS: Windows XP Personal Edition
    Dear Sirs,
    First at all thanks for reading this post. I am having the following issue. I am creating an application using html pages and servlets. I am using Chinese and English languages on them (html encoding UTF-8).
    I created a project in Netbeans and added an idex.html screen reporting to a servlet. Both index.html and in the servlet generated html page contains the line:
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    Additional, I setup the character code settings in Netbeans:
    (tools-options-Java sources-Expert-default encoding=UTF-8
    When I run the project, index.html displays itself perfectly, with the Chinese characters displayed properly. The problem comes when the html created servlet is displayed, which instead of the Chinese characters some strange characters are displayed (�� instead of Chinese).
    I have tried different encodings from http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html without any luck. I also setup the encoding of the file itself (using right click-properties in the project menu of Netbeans).
    Also, when I am editing the servlet, the characters are displayed properly. I type them directly without any issue, but then the display is wrong at runtime.
    Also, just in case this have something to do with the problem, my PC was bought in US, therefore the default character set is not Chinese. I had to install the Chinese typing stuff later on. But like I said earlier, the html page is displayed properly, so I really think is some problem with Netbeans.
    After a week trying to find a solution, I decided to post it here in the hopes that someone will show me the way of the light.
    Thanks in advance for any ideas or help provided
    Aral.

    Hi, thanks for your help. However I think the problem his more complex than it seems. Here is my doPost method (the important parts anyway):
    response.setCharacterEncoding("UTF-8"); //Not necessary because the next line should take care of it, but anyways...
    response.setContentType("text/html; charset=UTF-8; pageEncoding=UTF-8");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<meta http-equiv='Content-Language' content='en-us'>");
    out.println("<meta http-equiv='Content-Type' content='text/html; charset=utf-8; pageEncoding=utf-8'>"); //Again not necessary line, but anyways
    out.println("<title>Servlet</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("this is a test &#20320;&#22909; this is a test");
    out.println("</body>");
    out.println("</html>");
    out.close();
    This servlet is called from a html file. Also, when I load this in the browser, I right click on the screen and I can see that UTF-8 is setup allright. Doing some detective job I found that:
    - If the editor displays the characters perfectly and...
    - Other html pages (no servlets) in the same application can display chinese characters well and...
    - I have configured the encoding as UTF-8 in the servlet properties and in general properties and...
    - The file "web.xml" contains the encoding UTF-8 in its first line then...
    ...my only guess is that something goes wrong during the building of the project itself (ant?). Unfortunately I have no idea about configuring ant to that level, but I began to think that the problem may be there, during the compilation...
    Any ideas?
    Once more, thanks for any help or advice provided.
    Aral.

  • Pdf links will not open in new browser window

    I have created a pdf document in Acrobat 9 Pro that is password protected. You must enter the password to open it. In this document there are perhaps 15 links to other pdf documents. I set up each of the links to open in a new window. The links work as expected in Acrobat, each opening in a new window, however, when I posted the documents to the web, the links open in the same window as the original document. This would not be a big issue if the original document were not password protected, but each time the user clicks on a link, it takes him out of the original document. To get back to the original document requires re-entering the password. This is a major irritation with so many links.
    I know that you can set Acrobat to display the documents in its own window rather than in the browser, but my users don't know that. Control clicking on a pdf link does not open it in a new window as it would with an HTML link. Is there a simple fix to this problem that does not involve user intervention?

    Well, I came up with a solution, thanks to Ted Padova who offers a simple JavaScript solution on his blog at http://www.acrobatusers.com/blogs/tedpadova/opening-pdfs-new-browser-windows.
    The solution is clearly laid out even for beginners, if you know how to create a link or button.
    It seems to me that a prime objective of Adobe in developing Acrobat would be to have it behave the same way in free-standing mode and as a plug-in. In this case it does not, and obviously, it has not for the last forty-eleven years that Acrobat has been on the market. Maybe some day they will get around to a fix for this obvious problem. In the meantime, read Ted's blog and be happy we have guys like him who can solve these problems.

  • PDFs do not open in the browser since IE11

    Hi,
    since the IE11 is installed the PDFs do not open in the browser with Adobe Reader, but directly in Adobe Reader.
    The PDFs can be filled but not saved online because they are not open in IE.
    If I disable the PlugIn in IE11 and activate again it works again indefinitely.
    Can you help me?
    PS: translated with Google Translate
    Thanks

    StolzeR wrote:
    If I disable the PlugIn in IE11 and activate again it works again indefinitely.
    This, to me, sounds like it's working.  Or perhaps a problem with the translation?

  • I have Firefox 10.0.2. and OSX 10.6.8. and the latest PDF adobe reader, and still can not open with the browser PDF files.Can someone help,pls?Thanx

    Dear Ones,
    I have Firefox 10.0.2. and OSX 10.6.8. and the latest PDF adobe reader, and still can not open with the browser PDF files.Can someone help,pls?Thanx

    see if this is helpful : [http://support.mozilla.org/en-US/kb/Opening%20PDF%20files%20within%20Firefox Opening PDF files within Firefox]
    thank you
    Please mark "Solved" the answer that really solve the problem, to help others with a similar problem.

  • Safari won't display pdf in browser and I do not have adobe reader or ply ins

    I've been checking the posts and all the discussions/questions and answers but the only thing I have been able to find about problems displaying pdfs in browser have to do with adobe plug-ins. I never had adobe reader and checked in /library/internet plug ins and never found those plug ins. I then downloaded and installed adobe reader X and got rid of the plug ins in the library and that still has not solved the problem. Whenever I click on a link for a pdf it just automatically downloads the pdf. I just want to view the pdfs in the browser.
    Thanks for the help

    Hi,
    You probably won't have to reinstall Safari. Two things you can try. If you open Adobe Reader and go into the 'Internet' section of its preferences, you should be able to disable the browser plug-in. Some times that alone isn't enough, in which case, browse to HD/Library/Internet Plug-ins/ and move the Adobe plugin out of the folder. Restart Safari for the changes to take effect.
    Yang

  • Tricky - PDF file not Opening from Web Browser based application

    Hi Guys,
    Just a brief history about the issue:
    At my client site everything was fine when IE7 was there and everybody were able to open PDF files from web applications in browsers. But after a IE8 upgrade, things changed and customers are facing problems. All are Windows XP SP3 machines
    Issue: If they try to open a pdf file from the browser it just stucks at 0% and hangs with "Cancel" button. Even if they try to save that file it tell downloading and hangs again in the screen without downloading the file.
    Initial fix:
    Open Adobe Reader
    -> select the menu "Edit"
    -> select "Preferences"
    -> select the Category "Internet"
    -> set the indicator "Display PDF in browser"
    -> Reboot the machine
    This fix worrked for some people but many user are still experiencing the same thing even after changing the setting many times.
    Friends, Is there anything else might be creating the trouble here. Please let me know, and why it is that for some systems it is working and for it is not ?
    Thanks,

    There was a browser bug with IE in the past that seemed to span several browser versions.  It had to do with the interaction of the browser and the webserver.  The short version is that I had to toggle the caching option on the folder.
    Here's what I ended up doing for my client:
    Move their PDF documents into a subfolder called forms and all Flash animations into a subfolder called flash
    Marked all folders in the site to "Expire Immediately" (IIS -> highlight root folder -> Properties)
    Individually marked the "/forms" and "/flash" folders to toggle this caching option
    In this way, it allowed dynamic pages to deliver non-cached content (from the server's perspective) and it allowed binary downloads like Flash animations and PDF files to work as expected without errors.  The bug has to do with the cache-negotiation handshaking that goes on between the browser and server.
    This may not be what you're seeing but it's good to remember because I've seen it often:  the settings that you'd use to optimize a web applications don't seem to work for binary downloads like a PDF document.

  • Preview does not display pdf properly

    I have OS X 10.5.8 and Preview 4.2. Preview will not display a bank statement properly. Most of the content is missing. I initially thought this was the bank's fault, but the pdf statement displays OK on my work Mac using Adobe Acrobat Professional. On Preview, howerver, at work (OS X 10.4) it also does not display properly.
    Can anyone suggest a fix, or does Apple read these discussions...? Thanks. Graham

    "Preview is meant for previewing PDFs generated by OSX applications for printing.
    OSX uses its own code to generate and display PDFs, not Adobe's code.
    Adobe has been adding features to its PDF code that is used by some non-Apple software.
    PDFs generated by such software may not display correctly with Preview, but will work with the latest Adobe Reader."
    (courtesy of Malcolm Rayfield in this thread https://discussions.apple.com/message/12739728#12739728 )
    So, download and install the latest free Adobe Reader on your home Mac for these statements.
    Stefan

  • Safari does not display pdf's properly...

    MacMini 2010, OS 10.6.8, Safari 5.1.10
    Safari is not displaying pdf's properly that I can see perfectly in Chrome and Firefox...I get this weird pattern of black shapes....
    Works OK on my laptop OS 10.7.5, Safari 6.1.1 (after I allow it to access Adobe Reader...)
    Any ideas? The pdfs are printed/made from MS word docs. The header is a placed image. Also attaching screen shot from FF.
    Thanks

    Try this ...
    Open a Finder window then from the menu bar click Go > Go to Folder
    Type or copy paste the following:
    /Library/Internet Plug-Ins
    Click Go.
    If you see the:  AdobePDFViewer plugin in the Internet Plug-Ins folder, move it to the trash.
    Restart your Mac and try opening a PDF file.

Maybe you are looking for