[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

HttpServletResponse Returns scrambled content

Posted on 2011-03-24
3
Medium Priority
?
354 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:
Gurvinder Pal Singh earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
A solution for Fortify Path Manipulation.
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.

649 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