Jsp [tip] used for direct download files rather than open in the browser function

  Abstract: [tip] jsp used for direct download files rather than open in the browser function 

  <% / / Example: / / download image 
  String root = getServletContext (). GetRealPath ("/"); String path = request. GetParameter ( "path"); String name = request. GetParameter ( "name"); 
  Response. SetContentType ( "unknown"); response. AddHeader ( "Content-Disposition", "filename = \" "+ name +" \ ""); 
  Try (java.io.OutputStream os = response. GetOutputStream (); java.io.FileInputStream fis = new java.io. FileInputStream (root path + + name); 
  Byte [] b = new byte [1024]; int i = 0; 
  While ((i = fis. Read (b))> 0) (os. Write (b, 0, i);) 
  Fis. Close (); os. Flush (); os. Close ();) catch (Exception e) ()%> 

  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: ,

Releated Java Articles

Comments

Leave a Reply