title: Download image on clicking an image
body: <p>I want to download image on click.  I had set content type but I couldn't write image in  response. In controller I get URL of image.</p>
  
  <pre><code>String image=myimageUrl;
  File file = new File(image);  
  String contentType = getServletContext().getMimeType(file.getName());
  response.setBufferSize(DEFAULT_BUFFER_SIZE);
  response.setContentType(contentType);
  response.setHeader("Content-Length", String.valueOf(file.length()));
  </code></pre>
  
  <p>For writing into response I used this code </p>
  
  <pre><code>DataInputStream input = new DataInputStream(new FileInputStream(file));
  ServletOutputStream output  = response.getOutputStream();
  </code></pre>
  
  <p>Here input returns <code>null</code>.</p>
  
  <p>How to resolve this problem?</p>