%@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 ( "出現(xiàn)IOException." + e );
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
return;
%>
您可能感興趣的文章:- JSP生成WORD文檔,EXCEL文檔及PDF文檔的方法
- jsp頁(yè)面中顯示word/excel格式的文檔的方法
- jsp導(dǎo)出excel并支持分sheet導(dǎo)出的方法
- JSP導(dǎo)出Excel文件的方法
- JSP上傳excel及excel插入至數(shù)據(jù)庫(kù)的方法
- Jsp中的table多表頭導(dǎo)出excel文件具體實(shí)現(xiàn)
- jsp實(shí)現(xiàn)針對(duì)excel及word文檔的打印方法