• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

HttpServletResponse Returns scrambled content

Dear Experts,

I'm having a trouble with the following code, that when returned to the browser, shows the binary content of the file instead of the complete file.

I'm Using Seam 2.2 on Jboss EAP 5...

Thanks a lot!
Dave

public String print()
{
byte[] attachment = soh.getInvoicePdf(); // Oracle Blob Field

FacesContext facesContext = FacesContext.getCurrentInstance();
		HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
		        response.addHeader("Content-disposition", "attachment; filename=\"" +"invoice.pdf" +"\"");
                response.setContentLength(attachment.length);
           	    response.setHeader("Pragma", "no-cache");
        	    response.setHeader("Cache-Control", "no-cache");
        	    response.setDateHeader("Expires", 0);
        	    response.setContentType("application/pdf");
		try {
			ServletOutputStream os = null;
			os = response.getOutputStream();
			os.write(attachment);
			os.flush();
			os.close();
			facesContext.responseComplete();
						
		} catch(Exception e) {
			e.printStackTrace();
		}
		
		return null;
}		

Open in new window

0
dcrudo
Asked:
dcrudo
  • 2
1 Solution
 
Gurvinder Pal SinghCommented:
this link says that it will open a dialog box for all files except html and img
http://onjava.com/pub/a/onjava/excerpt/jebp_3/index3.html

0
 
dcrudoAuthor Commented:
It was a good idea but it didn't solve my issue...

i found the issue by chance:

 i was using an a4j button instead of an a:CommandButton.

Thanks for your quick reply!
Dave
0
 
dcrudoAuthor Commented:
BTW...since your link...was interesting...although didn't solve my problem...
i will accept your solution!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now