String file_path="文件路径"
File f;
if (file_path != "")
{
f = new File(file_path);
if (!f.exists()) {
return (mapping.findForward("nofile"));
}
BufferedInputStream br = new BufferedInputStream(
new FileInputStream(f));
byte[] buf = new byte[1024];
int len = 0;
response.reset();
response.setContentType("application/x-msdownload;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=文件名称.exe"); OutputStream out = response.getOutputStream();
while ((len = br.read(buf)) > 0)
out.write(buf, 0, len);
br.close();
out.close();
File f;
if (file_path != "")
{
f = new File(file_path);
if (!f.exists()) {
return (mapping.findForward("nofile"));
}
BufferedInputStream br = new BufferedInputStream(
new FileInputStream(f));
byte[] buf = new byte[1024];
int len = 0;
response.reset();
response.setContentType("application/x-msdownload;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=文件名称.exe"); OutputStream out = response.getOutputStream();
while ((len = br.read(buf)) > 0)
out.write(buf, 0, len);
br.close();
out.close();
解决方案 »
- 邮箱服务器获取账户
- MyEclipse官方网站打不开啊
- 请教一个tomcat的问题
- 用ssh建的论坛怎么才能发布到网络上去
- 诡异问题!在weblogic下运行得好好的web service在weblogic 7下竟然报404找不到错误!
- 被Deprecated的方法HttpUtils.getRequestURL(request)可以用什么方法来替代呢?
- 100分跪求Tomcat apache Soap 配置问题,高手帮忙呀,我按网上的说法配了,为什么就是不行呢?
- Eclipse+Jboss开发中的问题,急!!!!!
- 在jboss+tomcat中,如何用jsp调用另外一台机器上部署的ejb?
- maven项目中内嵌的tomcat的参数maxHttpHeaderSize在哪里配置
- webwork怎样从数据库读图片到jsp中
- spring+struts+hibernate问题
这里把头改称一个不认识的
比如
response.setContentType("application/download;charset=UTF-8");
Doc ,xls ,txt等文件,就不会直接打开的
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD><body style="font-size:10pt;font-family:arial;" background="../resources/images/mis_images/titleDH.gif">
µ¼³ö³Éexcel¸ñʽ£º
<p>
<OBJECT classid="clsid:0002E510-0000-0000-C000-000000000046" height=180 id=Spreadsheet1
style="LEFT: 0px; TOP: 0px" width="100%" VIEWASTEXT>
<!--PARAM NAME="HTMLURL" VALUE="ini.htm"-->
<PARAM NAME="DataType" VALUE="HTMLURL">
<PARAM NAME="AutoFit" VALUE="0">
<PARAM NAME="DisplayColHeaders" VALUE="-1">
<PARAM NAME="DisplayGridlines" VALUE="-1">
<PARAM NAME="DisplayHorizontalScrollBar" VALUE="-1">
<PARAM NAME="DisplayRowHeaders" VALUE="-1">
<PARAM NAME="DisplayTitleBar" VALUE="0">
<PARAM NAME="DisplayToolbar" VALUE="-1">
<PARAM NAME="DisplayVerticalScrollBar" VALUE="-1">
<PARAM NAME="EnableAutoCalculate" VALUE="-1">
<PARAM NAME="EnableEvents" VALUE="-1">
<PARAM NAME="MoveAfterReturn" VALUE="-1">
<PARAM NAME="MoveAfterReturnDirection" VALUE="0">
<PARAM NAME="RightToLeft" VALUE="0">
<PARAM NAME="ViewableRange" VALUE="1:65536">
</OBJECT>
</p>
</body>
</HTML>