package jsp;

import java.io.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Download
 */
@WebServlet("/Download")
public class Download extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Download() {
        super();
        // TODO Auto-generated constructor stub
    }

    public void doGet( HttpServletRequest request,HttpServletResponse response) {  
        try {  
            
            File file = new File("./dt.jar");  
          
            String filename = file.getName();  
         
            @SuppressWarnings("unused")
			String ext = filename.substring(filename.lastIndexOf(".") + 1)  
                    .toUpperCase();  
      
          
            InputStream fis = new BufferedInputStream (new FileInputStream("./dt.jar"));  
            byte[] buffer = new byte[fis.available()];  
            fis.read(buffer);  
            fis.close();  
           
            response.reset();  
          
            response.addHeader("Content-Disposition", "attachment;filename="  
                    + new String(filename.getBytes()));  
            response.addHeader("Content-Length", "" + file.length());  
            OutputStream toClient = new BufferedOutputStream(  
                    response.getOutputStream());  
            response.setContentType("application/octet-stream");  
            toClient.write(buffer);  
            toClient.flush();  
            toClient.close();  
        } catch (IOException ex) {  
            ex.printStackTrace();  
        }  
        return ;  
    }  
    
    
    
    /**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
//	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
最近下载更多
qiuqiuqiu111  LV4 2022年11月29日
yymmyy  LV1 2021年10月28日
ewofl888  LV1 2021年6月21日
2539788229  LV4 2021年1月4日
ahly88  LV1 2020年11月7日
jiayouyy  LV8 2020年6月1日
柠檬味汽水  LV1 2020年4月13日
3478CH  LV9 2019年11月21日
2308478564  LV15 2019年11月18日
1219610676  LV4 2019年9月28日
最近浏览更多
WHY-small  LV15 2023年12月29日
lanana  LV1 2023年12月22日
321170193  LV6 2023年11月12日
sdfgsdfg  LV2 2023年10月23日
monolog  LV4 2023年5月11日
月光skr  LV3 2023年4月9日
小逸夜  LV4 2022年12月27日
qiuqiuqiu111  LV4 2022年11月29日
chengchengya  LV2 2022年10月2日
13112360  LV2 2022年9月27日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友