jsp 如何实现下载文件的功能 第一步:创建 Servlet 第二步:写代码 public class FielDownLoad extends HttpServlet { /** * Constructor of the object. */ public FielDownLoad() { super(); } /** * Destruction of the servlet.
*/ public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here } /** * The doGet method of the servlet.
* * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } /** * The doPost method of the servlet.
* * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String filename = request.getParameter("file_name"); if (filename == null) filename = ""; filename = filename.trim(); InputStream inStream = null; String attchname = ""; byte[] b = new byte[100]; int len = 0; try { attchname = getAttachName(filename); //取得附件的名称 filename = getRealName(request, filename); //取得附件的全路径 if (filename == null) { response.setContentType("text/html; charset=GBK"); response.getWriter().print("文件不存...