[jboss-user] [JBoss Seam] - File(data) Download problem...

waheed.murad do-not-reply at jboss.com
Thu Mar 1 07:18:37 EST 2007


i am using seam-gen. i am trying to dowload a file or data from server as file. my code is 

FACELETS CODE:
<h:commandButton value="donwload file" actionListener="#{ERegReportHandlerAction.downloadReportFile}"/>     	

Sessionbean Function:

public void downloadReportFile(){
    	
    ExternalContext exContext=FacesContext.getCurrentInstance().getExternalContext();
    javax.servlet.http.HttpServletResponse response = ((javax.servlet.http.HttpServletResponse)exContext.getResponse());
    	
    	//response.setContentType("application/x-download");
    	response.setContentType("text/plain");
    	response.setHeader("Content-Disposition", "attachment; filename=" + "test.csv");
    	

    	try{
    		OutputStream out = response.getOutputStream( );
    	
    		byte[] arr=("This is the file data.").getBytes();
    		response.setContentLength(arr.length);
    		out.write(arr);
    		out.close();
    	}catch(Exception e){
 		System.out.println("Error: " + e.getMessage() );
    	}
    	
    }

--------------------------------------------------------------------
file is downloaded but when i open it, i have the contents written by me(i.e This is the file data) plus the whole html page source code from where i pressed the download button. 
any help regarding this plz.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4024221#4024221

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4024221



More information about the jboss-user mailing list