资源简介

idea+Tomcat,java实现简单的文件的上传、下载、删除,源程序,可直接运行!上传的文件保存在idea自动生成的upload_project\out\artifacts\upload_project_war_exploded\WEB-INF\upload目录下

资源截图

代码片段和文件信息

package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;

/**
 * @author asus
 * @create 2019-12-11 21:54
 */
@WebServlet(“/servlet/DeleteServlet“)
public class DeleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request HttpServletResponse response) throws ServletException IOException {
        //得到要删除的文件名
        String fileName = request.getParameter(“filename“);  //23239283-92489-阿凡达.avi
        //获取文件所在的路径
        String fileSaveRootPath = this.getServletContext().getRealPath(“/WEB-INF/upload“);
        //得到要删除的文件
        File file = new File(fileSaveRootPath + “\\“ + fileName);
        file.delete();
        request.getRequestDispatcher(“/servlet/ListFileServlet“).forward(request response);
    }

    @Override
    protected void doPost(HttpServletRequest request HttpServletResponse response) throws ServletException IOException {
        doGet(request response);
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-12-11 21:06  文件上传下载的项目\
     目录           0  2019-12-11 10:46  文件上传下载的项目\upload_project\
     目录           0  2019-12-22 09:59  文件上传下载的项目\upload_project\.idea\
     目录           0  2019-12-10 17:13  文件上传下载的项目\upload_project\.idea\artifacts\
     文件         531  2019-12-10 17:13  文件上传下载的项目\upload_project\.idea\artifacts\upload_project_war_exploded.xml
     文件         205  2019-12-11 09:38  文件上传下载的项目\upload_project\.idea\encodings.xml
     目录           0  2019-12-10 23:52  文件上传下载的项目\upload_project\.idea\libraries\
     文件         290  2019-12-10 23:46  文件上传下载的项目\upload_project\.idea\libraries\lib.xml
     文件         294  2019-12-10 23:52  文件上传下载的项目\upload_project\.idea\libraries\lib__2_.xml
     文件         278  2019-12-10 17:13  文件上传下载的项目\upload_project\.idea\misc.xml
     文件         275  2019-12-10 17:13  文件上传下载的项目\upload_project\.idea\modules.xml
     文件       28800  2019-12-22 09:59  文件上传下载的项目\upload_project\.idea\workspace.xml
     目录           0  2019-12-11 10:46  文件上传下载的项目\upload_project\out\
     目录           0  2019-12-11 10:46  文件上传下载的项目\upload_project\out\artifacts\
     目录           0  2019-12-22 09:51  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\
     目录           0  2019-12-22 09:45  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\WEB-INF\
     目录           0  2019-12-11 10:46  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\WEB-INF\classes\
     目录           0  2019-12-11 22:08  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\WEB-INF\classes\servlet\
     文件        1835  2019-12-11 22:07  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\WEB-INF\classes\servlet\DeleteServlet.class
     文件        3165  2019-12-11 22:07  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\WEB-INF\classes\servlet\DownLoadServlet.class
     文件        2644  2019-12-11 22:07  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\WEB-INF\classes\servlet\ListFileServlet.class
     文件        4556  2019-12-11 22:07  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\WEB-INF\classes\servlet\UploadHandleServlet.class
     目录           0  2019-12-11 22:08  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\WEB-INF\lib\
     文件       72446  2018-12-24 02:06  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\WEB-INF\lib\commons-fileupload-1.4.jar
     文件      214788  2017-10-15 12:00  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\WEB-INF\lib\commons-io-2.6.jar
     文件      414240  2016-05-16 12:16  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\WEB-INF\lib\jstl-1.2.jar
     目录           0  2019-12-22 09:56  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\WEB-INF\upload\
     文件        9340  2019-12-11 22:14  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\WEB-INF\upload\高手.txt
     文件         401  2019-12-22 09:45  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\WEB-INF\web.xml
     文件         448  2019-12-11 00:29  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\download.jsp
     文件         302  2019-12-10 17:13  文件上传下载的项目\upload_project\out\artifacts\upload_project_war_exploded\index.jsp
............此处省略33个文件信息

评论

共有 条评论