Download Varbinary in a JSF webapp

I recently had to read a varbinary (sql server 2005) and download it from my JSF application…

Here is a method to do so, it recieves the file name  (string), the content (byte[]) and file extention (string).

Add this to the import section:

import javax.faces.context.FacesContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
public static void downloadVarbinary(String fileName,
            byte[] content, String extention) {
        try {
            HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext
            ServletOutputStream servletOutputStream = httpServletResponse
                    "attachment; filename=" + fileName + "." + extention);
            httpServletResponse.setContentLength((int) content.length);
        } catch (Exception e) {

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s