java - Zip multiple files, download it and then redirect to another page using servlet -


i have multiple files , want following things using servlet:

  1. zip multiple files.
  2. download it.
  3. then redirect servlet or jsp.

i have achieved steps 1 , 2 i'm getting error on step 3. using code:

/**  * @see httpservlet#httpservlet()  */ public downloadaj() {     super();     // todo auto-generated constructor stub }  /**  * @see httpservlet#doget(httpservletrequest request, httpservletresponse response)  */ protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {     // todo auto-generated method stub     list<string> filenames = new arraylist<string>();     //..code add urls list     filenames.add("e:/analyticsagent/avekbank.rar");     filenames.add("e:/analyticsagent/java_agent.jar");     //filenames.add("e:/analyticsagent/avanalytics.framework.zip");     byte[] buf = new byte[2048];     // create zip file     bytearrayoutputstream baos = new bytearrayoutputstream();     zipoutputstream out = new zipoutputstream(baos);     // compress files     (int i=0; i<filenames.size(); i++) {     fileinputstream fis = new fileinputstream(filenames.get(i).tostring());     bufferedinputstream bis = new bufferedinputstream(fis);     // add zip entry output stream.     file file = new file(filenames.get(i).tostring());     string entryname = file.getname();     out.putnextentry(new zipentry(entryname));     int bytesread;     while ((bytesread = bis.read(buf)) != -1) {     out.write(buf, 0, bytesread);     }     out.closeentry();     bis.close();     fis.close();     }     out.flush();     //baos.flush();     out.close();     //baos.close();      servletoutputstream sos = response.getoutputstream();      response.setcontenttype("application/zip");     response.setheader("content-disposition", "attachment; filename=\"myzip.zip\"");      //requestdispatcher dd = request.getrequestdispatcher("pricedetaildb");    // dd.forward(request, response);     sos.write(baos.tobytearray());     response.sendredirect("pricedetaildb");     baos.flush();     baos.close();     out.flush();     out.close();     sos.flush();      system.out.println("done zipping");  }  /**  * @see httpservlet#dopost(httpservletrequest request, httpservletresponse response)  */ protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {     // todo auto-generated method stub } 

by using code getting below mentioned error:

cannot call sendredirect() after response has been committed

how can perform redirection after zipping , download? please tell me through code snippets or ideas how can perform task.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -