在Servlet里下载文件的问题!

allenmaygu 2004-05-07 08:56:01
代码如下,
public void execPost(
HttpServletRequest req,
HttpServletResponse resp,
ZParameterParser paramParser)
throws ServletException, IOException, Exception {
try{
System.out.println("Start!");
resp.setContentType("application/JAR");
resp.setHeader("Content-Disposition", "attachment; filename=\"ElixirReport.jar\"");
FileInputStream fileInputStream = new FileInputStream("C:\\ElixirReport40/ElixirReport/core/ElixirReport.jar");
int i,j=0;
ServletOutputStream op = resp.getOutputStream();
byte[] temp = new byte[fileInputStream.available()];
while ((i=fileInputStream.read()) != -1) {
temp[j] = (byte)i;
}
op.write(temp);
fileInputStream.close();
op.flush();
op.close();
}catch(Exception e){
e.printStackTrace();
throw e;
}
}
文件是能下载,但打不开啊??
不知道是不是resp.setContentType("application/JAR")错了,但我不知道JAR文件设成什么类型??
哪位帮我看看啊??
...全文
45 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧