用JSP下载word文件(不会直接用IE打开)
2006-10-13 00:00
579 查看
<%@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;
%>
<%@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下载word文件(不会直接用IE打开)
- jsp页面 java 文件下载设置禁止IE直接打开配置问题
- jsp中让IE提示文件下载,而不是直接打开
- 不让IE直接打开word、PDF、EXCEL提示下载或打开
- ASP.NET直接下载一个文件,而不是在IE中打开它
- ASP.NET直接下载一个文件,而不是在IE中打开它
- weblogic服务上传word等文件直接打开问题解决 博客分类: web应用服务器 在weblogic上发布的web项目,测试中发现出现当上传word、excel、pdf等文件在下载的时候出现
- jsp文件在ie中打开时提示下载的错误
- JSP下载文件,直接下载文件保存到本地,不直接打开,没有乱码
- ASP.NET直接下载一个文件,而不是在IE中打开它
- ASP.NET直接下载一个文件,而不是在IE中打开它
- 在下载txt文件的时候不在IE里面直接打开,而是下载
- JSP下载文件,直接下载文件保存到本地,不直接打开,没有乱码
- JAVA文件下载,IE不提示下载,直接打开的解决方法
- 在ie直接打开word/excel文件(转贴)
- java 获取网络文件获取流下载,支持IE火狐 直接下载而不直接打开
- jsp 实现文件下载到客户端并可直接打开或保存
- asp.net中下载TEXT文件,而不是直接在IE中打开
- 文件链接没有弹出文件下载框, 且直接被IE打开(Openoffice 为例)