1.什么情况下会要文件下载
浏览器不能够直接解析的文件
2.什么情况下需要在服务器端编写文件下载的代码?
一般情况下,浏览器不能解析的代码需要编写文件下载的代码
因为浏览器的不同,像谷歌浏览器可以直接解析文件,ie浏览器不能直接解析文件,因此我们设置代码不让浏览器解析文件,而是下载文件。
新建一个download.html
再新建一个Servlet
***public class DownloadServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//取页面的参数用的,当页面的表单参数通过request里面传过来,就可以通过这个方法取出来
String filename = request.getParameter(“file”);
// 要下载的文件类型 MIME response.setContentType(this.getServletContext().getMimeType(filename));
// 告诉浏览器该文件不是直接进行解析,而是以下载的方式
// 在设置进去response中之前,可以先
如何将服务器的文件下载到本地
最新推荐文章于 2024-05-07 11:15:02 发布