在Servlet里下载文件的问题!
代码如下,
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文件设成什么类型??
哪位帮我看看啊??