Solved

HttpServletResponse Returns scrambled content

Posted on 2011-03-24
3
344 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
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
BTW...since your link...was interesting...although didn't solve my problem...
i will accept your solution!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now