Using JSP download word documents (not the direct use of open IE)

  Abstract: JSP download word documents (not the direct use of open IE) 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width="684" border="0"> <tr> <td width = " 402 "> <% @ page import =" java.util .*"%> 
  <% @ Page import = "java.io. *"%> 
  <% @ Page import = "java.net .*"%> 

<%
  String filename = ""; 
  If (request.getParameter ( "file")! = Null) ( 
  Filename = request.getParameter ( "file"); 
  ) 

  Response.setContentType ( "application / msword"); 
  Response.setHeader ( "Content-disposition", "attachment; filename =" + filename); 
  </ Td> <td width="272" align="center"> </ td> </ tr> </ table>? 

  BufferedInputStream bis = null; 
  BufferedOutputStream bos = null; 
  Try ( 
  Bis = new BufferedInputStream (new FileInputStream (getServletContext (). GetRealPath ( "/ dir1/dir2 /" + filename))); 
  Bos = new BufferedOutputStream (response.getOutputStream ()); 

  Byte [] = new byte buff [2048]; 
  Int bytesRead; 

  While (-1! = (BytesRead = bis.read (buff, 0, buff.length))) ( 
  Bos.write (buff, 0, bytesRead); 
  ) 
  ) Catch (final IOException e) ( 
  Out.println ( "IOException." + E); 
  Finally () 
  If (bis! = Null) 
  Bis.close (); 
  If (bos! = Null) 
  Bos.close (); 
  ) 
  Return; 
  %> Function TempSave (ElementID) (CommentsPersistDiv.setAttribute ( "CommentContent" document.getElementById (ElementID). Value); CommentsPersistDiv.save ( "CommentXMLStore");) function Restore (ElementID) (CommentsPersistDiv.load ( "CommentXMLStore") ; document.getElementById (ElementID). CommentsPersistDiv.getAttribute value = ( "CommentContent");) </ td> </ tr> <tr> 

  ↑ 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