top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

How to create a zip file and download in Java using Strut2?

+1 vote
94 views

I have a web application developed using Struts2. In my web application I have a link using which users can download a zip file. I need to create this zip file at run time based on some conditions. How can I do this in Struts2?

posted Mar 20, 2013 by Sudheendra

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

0 votes
 
Best answer

Use zipOutputStream to create zip file like following

ZipEntry entry = new ZipEntry( fileName ); // You have to give each entry a different filename
zipOutputStream.putNextEntry( entry );
byte buffer[] = new byte[ 1024 ]; // 1024 is the buffer size here, but it could be anything really
int count;
while( (count = inputStream.read( buffer, 0, 1024 ) ) != -1 ) {
    zipOutputStream.write( buffer, 0, count );
}

And then send the output to your struts.xml file for download...

answer Mar 21, 2013 by Nora Jones
Similar Questions
+3 votes

I am planning to use JFree Charts for my web application. I have a requirement to place multiple Charts (say multiple pie charts) on a single JSP page. How can I achieve using JFree Charts?

I am using Struts2 for building this web application.


Useful Links with Similar Problem
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#470/147, 3rd Floor, 5th Main,
HSR Layout Sector 7,
Bangalore - 560102,
Karnataka INDIA.
QUERY HOME
...