<% @ 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 );
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
Try {
Bis = new BufferedInputStream (new FileInputStream (getServletContext (). getRealPath ("" + filename )));
Bos = new BufferedOutputStream (response. getOutputStream ());
Byte [] buff = new byte [2048];
Int bytesRead;
While (-1! = (BytesRead = bis. read (buff, 0, buff. length ))){
Bos. write (buff, 0, bytesRead );
}
} Catch (final IOException e ){
System. out. println ("IOException." + e );
} Finally {
If (bis! = Null)
Bis. close ();
If (bos! = Null)
Bos. close ();
}
Return;
%>