On the Web page, if the address of our hyperlink corresponds to a JPG file, TXT file, etc., when clicking the link, the browser default is to open these files instead of downloading, then how to implement the default download.
Can be achieved by writing a download.jsp yourself.
<span style= "FONT-SIZE:18PX;" ><%@ page contenttype= "text/html; Charset=utf-8 "%><%@ page import=" java.net.* "%><%//get file name and path String filename = request.getparameter ( "FileName"); String filepath = request.getparameter ("filepath"); String displayfilename = urlencoder.encode (filename, "UTF-8"); try {response.setcontenttype ("Application/x-download" ); Response.setheader ("Content-disposition", "attachment;filename=\" "+ displayfilename +" \ "); RequestDispatcher dis = application.getrequestdispatcher (filepath + filename); if (dis! = null) { dis.forward (request,response); } Response.flushbuffer ();} catch (Exception e) { System.out.println ("Download canceled:" + filepath + filename);} out.clear (); out = Pagecontext.pushbody ();%></span>
when we want to link the picture (or other browser by default open format, here take the picture as an example), the corresponding file name and address into the download.jsp filename and filepath parameters, the specific wording as follows
<a class= "blue-line-a" href= "/packtool/download.jsp? filename=wingui.exe& filepath=http://127.0.0.1:8080/sharefolder/other/wingui.exe ">/other/WinGUI.exe</a>
In this way, we can implement the default download of the file, not the default browser open.
Picture implementation default download instead of Open Picture (Java edition)