标签:servlet 下载
代码实现:
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CodeReturn extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/jar");
ServletContext servletContext = getServletContext();
InputStream inputStream = servletContext.getResourceAsStream("/1.jar");
OutputStream outputStream = response.getOutputStream();
byte [] buff = new byte[1024];
int n = 0;
while((n = inputStream.read(buff)) != -1) {
outputStream.write(buff, 0, n);
}
outputStream.flush();
outputStream.close();
}
}
标签:servlet 下载
原文地址:http://blog.csdn.net/u010919133/article/details/45487141