<%@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;
%>
用jsp下载word文件(不会直接用ie打开)_jsp技巧
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 用jsp下载word文件(不会直接用ie打开)_jsp技巧
相关推荐
-      通过jdbc连接oracle的十大灵活技术_jsp技巧
-      jdbc之代码重复使用_jsp技巧
-      提升jsp页面响应速度的七大秘籍绝招_jsp技巧
-      jdbc连sql server数据库步骤及有一项操作已被挂起,需重新启动计算机解决办法_jsp技巧
-      解决jsp中使用request乱码问题_jsp技巧
-      详细的jsp分页(oracle+jsp+apache)_jsp技巧
-      jsp中与标签要用不同的方式获得数据库中的数据_jsp技巧
-      jsp2.0新特性_jsp文摘
