package servlet.*;
import java.io.*;
import java.servlet.*;
import javax.servlet.http.*;
public class FileDownloadServlet extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response)tthrows ServletException,IOException{
response.setContentType("application/jar");
//设置响应头,将响应头内容以指定的文件名存储到客户机上
response.setHeader("Content-Disposition","attachment;filename=servlet-api.jar");
File f=new File("C:\\servlet-api.jar");
FileInputStream is=new FileInputStream(f);
ServletOutputStream os=response.getOutputStream();
byte[]bytearray=new byte[1024];
int bytesread=0;
while((bytesread=is.read(bytearray))!=-1){
os.write(bytearray.0,bytesread);
}
os.flush();}
}
import java.io.*;
import java.servlet.*;
import javax.servlet.http.*;
public class FileDownloadServlet extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response)tthrows ServletException,IOException{
response.setContentType("application/jar");
//设置响应头,将响应头内容以指定的文件名存储到客户机上
response.setHeader("Content-Disposition","attachment;filename=servlet-api.jar");
File f=new File("C:\\servlet-api.jar");
FileInputStream is=new FileInputStream(f);
ServletOutputStream os=response.getOutputStream();
byte[]bytearray=new byte[1024];
int bytesread=0;
while((bytesread=is.read(bytearray))!=-1){
os.write(bytearray.0,bytesread);
}
os.flush();}
}