java - Downloading set of XML files as a zip file in JSF -


i have string array in each string contains xml content.i have put each string file , have download xmls zip file.

how can achieve using jsf.

example code:

string content="<?xml version="1.0" encoding="utf-8"?> <head> <car>     <model>i10</command>     <price></target>  </car></head>";  httpservletresponse response =                (httpservletresponse) facescontext.getcurrentinstance()                    .getexternalcontext().getresponse();        zipoutputstream zos = new zipoutputstream(response.getoutputstream());        zipentry ze= new zipentry("spy.log");        zos.putnextentry(ze);         zos.write(content.getbytes());        zos.closeentry();          response.setcontenttype("application/zip");         response.setheader("content-disposition", "attachment;filename=fyi.zip");        response.setheader("content-transfer-encoding", "binary");        response.getoutputstream().flush();        response.getoutputstream().close();        facescontext.getcurrentinstance().responsecomplete(); 

but unable download attachment.please guide me!!

the headers must done first. (as in http header lines written first, , content.)

content.getbytes("utf-8").

do not close response output stream. call zos.finish() @ end (does not close opposed zos.close() - 1 of both have called zip). closing response output stream responsibility of container.

(make sure nothing output besides code above.)


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -