Solved

HttpServletResponse Returns scrambled content

Posted on 2011-03-24
3
350 Views
Last Modified: 2012-08-13
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
Comment
Question by:dcrudo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 35206805
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
 
LVL 1

Author Comment

by:dcrudo
ID: 35207647
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
 
LVL 1

Author Comment

by:dcrudo
ID: 35207654
BTW...since your link...was interesting...although didn't solve my problem...
i will accept your solution!
0

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question