Results 1 to 6 of 6

Thread: Servlet problem to send pdf

  1. #1
    Join Date
    Dec 2009
    Posts
    296

    Servlet problem to send pdf

    Hello,
    I use a servlet to display documents (jpeg, pdf, flv) in firefox, it works well for pictures and videos but I have problems with pdf, indeed ClientAbortException exception: java.net.SocketException rose, I tested my application in two different servers, one Linux and one Windows. Under windows, despite the fact that the exemption is lifted the pdf is still occurring, not Linux. Another strange, the servlet that handles the sending of a document seems to be called twice (it is yet called once in the code) when you want to load a pdf then it is called once for pictures and video. If someone has an idea please post it.
    Last edited by Gunner 1; 12-01-2010 at 10:41 AM.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: Servlet problem to send pdf

    Hello
    Can you show the code for your servlet. With regard to IE 6 in any case I do not know if it was corrected later, but with the pdf you've got a bug in double call the url associated. If you post the code or an import part of the code, it would be easier for us to explain you much easily. It is not that you have to past the full code, just an important part or where is logic is in the code, you can past it.

  3. #3
    Join Date
    Dec 2009
    Posts
    296

    Re: Servlet problem to send pdf

    Hello,
    Here is my servlet code
    Code:
    Public class Servlet_File exends HttpServlet {
         Public void init(ServletConfig config) throws ServletException {
            great.init(config);
        }
        Public void destroy() {
        }
        
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {
        	
            String ty = request.getParameter( "ty" );
            String fn = request.getParameter( "fn" );
            String ex = request.getParameter( "ex" );
    
            Servlet_Utils.Send_file(true, response, fn, ty +"/"+ ex,1024,8);
        }
       protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {
            processRequest(request, response);
        }
       
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {
            processRequest(request, response);
        } 
    }

  4. #4
    Join Date
    Dec 2009
    Posts
    296

    Re: Servlet problem to send pdf

    Hi
    This is the code for function Send_file called to retrieve the file
    Code:
        Public static void Send_file( Final boolean usePersistantConnexions,
        	    Final HttpServletResponse res,
        	    Final File imf,
        	    Final String conty,
        	    Final int bls,
        	    Final int numbl
    	     ) throws IOException {
        	        try {
        	            Final ServletOutputStream sos = res.getOutputStream();
               res.setContentType( conty );
    
        res.setHeader( "Content-Disposition", "attachment; filename =" + ImageFile.getName() );    	   
        	            if ( usePersistantConnexions )
        	                res.setContentLength( ( int ) imf.length() );
        BufferedInputStream bis = null;
        	            try {
        	                a = new BufferedInputStream( new FileInputStream( imf ) );
      	                
        	                byte [] buf = new byte[ numbl * bls ];
        	                int bytesRead;
    
        	                while( ( bytesRead = ca.read( buf ) ) != -1 )
        	                    sos.write( buf, 0, BytesRead );
        	            }
        	            finally {
        	                if ( Encore! = null )
        	                    ca.close();
        	            }
        	            
        	            if ( Encore! = null ) {
        	                ca.close();
        a = null;
        	            }
        	            res.flushBuffer();
        sos.flush();
        sos.close();
        	            
        	        } catch( Final Exception e ) { e.printStackTrace();  }
        	    }

  5. #5
    Join Date
    May 2008
    Posts
    2,012

    Re: Servlet problem to send pdf

    Hey,
    First time I see a try / finally without catch. You have some duplication in your code
    Code:
    finally {
        	                if ( Encore! = null )
        	                    ca.close();
        	            }
        	            
        	            if ( Encore! = null ) {
        	                ca.close();
        a = null;
        	            }
    The code will always be finally executed contrary to the code that follows.
    Code:
    finally {
        	                if ( Encore! = null )
        	                    ca.close();
     a = null;
         	            }
    catch in the bottom of it you fail a throw e. why have you wrote all your attributes Send_file method in Final ?

  6. #6
    Join Date
    Dec 2009
    Posts
    296

    Re: Servlet problem to send pdf

    Hi
    Actually, I took an existing code and I have not really looked, saw that it worked when I tested I'm not gone far I stupidly used without analysis. I take notes of your comments and I'll fix that. Thanks for your help. If you have any more suggestions for me or you have any guide for me then I will be more happy.

Similar Threads

  1. Replies: 5
    Last Post: 21-07-2010, 01:26 AM
  2. JSP and Servlet problem
    By Devabrata in forum Software Development
    Replies: 5
    Last Post: 21-07-2010, 12:12 AM
  3. What is Servlet container?
    By Sonam Goenka in forum Software Development
    Replies: 5
    Last Post: 05-02-2010, 08:13 AM
  4. Problem While Passing Parameter To Servlet In JSP
    By Jagdish Gada in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 02:33 PM
  5. Problem to send e-mails
    By Sukhvinder in forum Technology & Internet
    Replies: 4
    Last Post: 19-01-2009, 11:11 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,880,050.90176 seconds with 17 queries