Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Directory Download Servlet(Need your help asap!)

Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Folks,
Could you please help me sort out this problem urgently.
Well I am falling short of the required time to do it myself!
Hence it is a request.I will be much grateful to anyone who can just help me out .
I am wanting to download an entire directory of images
and want to do so using the com.oreilly.servlet package.
I am also using the ServletUtils class to get it done.
My code is divided into 2 parts
import javax.servlet.*;
import javax.servlet.http.*;
import com.oreilly.servlet.*;
public class DownloadFile extends HttpServlet{
HttpServletResponse res;
ServletOutputStream out;
boolean endedLastResponse = true;

public void init(HttpServletResponse response) throws ServletException,IOException {
// Save the response object and output stream
res = response;
out = res.getOutputStream();
// Set things up

public void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException
ServletOutputStream out = resp.getOutputStream();

ServletUtilsa.returnFile(req.getRealPath("/Dir/"), out);

MultipartResponse multi = new MultipartResponse(res);
out.println("On your mark");
try { Thread.sleep(1000); } catch (InterruptedException e) { }
out.println("Get set");
*********End of**************

import java.lang.reflect.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ServletUtilsa {
public static void returnFile(String filename,OutputStream out)
throws FileNotFoundException, IOException {
// A FileInputStream is for bytes
FileInputStream fis = null;
File f1=new File(filename);
String s[]=f1.list();

int i;
for (i=0;i<s.length;i++)
byte[] buf=new byte[4 * 1024];

try {
fis = new FileInputStream(filename);
byte[] buf = new byte[4 * 1024]; // 4K buffer
int bytesRead;
while ((bytesRead = != -1) {
out.write(buf, 0, bytesRead);
finally {
if (fis != null) fis.close();

**********End of*************
Both the files get compiled but I get a NullPointer Exception at output .I want to rectify it and want the popup dialog Box to be displayed for the user to download the directory of Images.
As you can see the directory is specified in this statement.
ServletUtilsa.returnFile(req.getRealPath("/Dir/"), out);
I need a workable solution have the source code as is!Many many thanks.
P.S: Please post the entire code either at my email address:
or here whichever is convenient

Squanch that. And squanch this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic