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
Post a Comment