top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

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

+1 vote
613 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 LinkedIn 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.

...