Posts

Showing posts with the label download

Downloading a file from web application

Image
      This post explains developing a web application which allows requestor to download a file. Here web app will have a servlet which streams requested file to requestor. follow the step to develop it using NetBean 6.8 1. Create a web application [ refer previous posts ] 2.Create a Servlet and add the code given below in doGet method      String filePath =null;      int length =0;        //accept file name as parameter         String fileName = request.getParameter("FILE_NAME");         InputStream is = getServletContext().getClassLoader().getResourceAsStream("/"+fileName);         if(is == null){             PrintWriter writer = response.getWriter();   ...