?
Solved

HttpServletResponse Returns scrambled content

Posted on 2011-03-24
3
Medium Priority
?
352 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
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…
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.
Suggested Courses

770 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