01 | package jsp; |
02 |
03 | import java.io.*; |
04 |
05 | import javax.servlet.ServletException; |
06 | import javax.servlet.annotation.WebServlet; |
07 | import javax.servlet.http.HttpServlet; |
08 | import javax.servlet.http.HttpServletRequest; |
09 | import javax.servlet.http.HttpServletResponse; |
10 |
11 | /** |
12 | * Servlet implementation class Download |
13 | */ |
14 | @WebServlet ( "/Download" ) |
15 | public class Download extends HttpServlet { |
16 | private static final long serialVersionUID = 1L; |
17 | |
18 | /** |
19 | * @see HttpServlet#HttpServlet() |
20 | */ |
21 | public Download() { |
22 | super (); |
23 | // TODO Auto-generated constructor stub |
24 | } |
25 |
26 | public void doGet( HttpServletRequest request,HttpServletResponse response) { |
27 | try { |
28 | |
29 | File file = new File( "./dt.jar" ); |
30 | |
31 | String filename = file.getName(); |
32 | |
33 | @SuppressWarnings ( "unused" ) |
34 | String ext = filename.substring(filename.lastIndexOf( "." ) + 1 ) |
35 | .toUpperCase(); |
36 | |
37 | |
38 | InputStream fis = new BufferedInputStream ( new FileInputStream( "./dt.jar" )); |
39 | byte [] buffer = new byte [fis.available()]; |
40 | fis.read(buffer); |
41 | fis.close(); |
42 | |
43 | response.reset(); |
44 | |
45 | response.addHeader( "Content-Disposition" , "attachment;filename=" |
46 | + new String(filename.getBytes())); |
47 | response.addHeader( "Content-Length" , "" + file.length()); |
48 | OutputStream toClient = new BufferedOutputStream( |
49 | response.getOutputStream()); |
50 | response.setContentType( "application/octet-stream" ); |
51 | toClient.write(buffer); |
52 | toClient.flush(); |
53 | toClient.close(); |
54 | } catch (IOException ex) { |
55 | ex.printStackTrace(); |
56 | } |
57 | return ; |
58 | } |
59 | |
60 | |
61 | |
62 | /** |
63 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) |
64 | */ |
65 | // protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
66 |
67 | // } |
68 |
69 | /** |
70 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) |
71 | */ |
72 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
73 | // TODO Auto-generated method stub |
74 | } |
75 |
76 | } |

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日