From c568da745f1e29c1d65d5b775c24211b57a5d18d Mon Sep 17 00:00:00 2001 From: Kane Date: Tue, 24 Jan 2023 00:35:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E8=BF=9B=E5=BA=A6=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/FileUpload/FileUpload.java | 24 ++++++++++++++++--- .../xim/web/filters/token/TokenFilter.java | 4 ++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/企业级管理系统/java/AdminSys/src/main/java/com/cpic/xim/web/controllers/FileUpload/FileUpload.java b/企业级管理系统/java/AdminSys/src/main/java/com/cpic/xim/web/controllers/FileUpload/FileUpload.java index 5427e1e..568fbbd 100644 --- a/企业级管理系统/java/AdminSys/src/main/java/com/cpic/xim/web/controllers/FileUpload/FileUpload.java +++ b/企业级管理系统/java/AdminSys/src/main/java/com/cpic/xim/web/controllers/FileUpload/FileUpload.java @@ -2,7 +2,7 @@ * @Author: Kane * @Date: 2023-01-22 23:11:26 * @LastEditors: Kane - * @LastEditTime: 2023-01-23 23:22:10 + * @LastEditTime: 2023-01-24 00:35:02 * @FilePath: \AdminSys\src\main\java\com\cpic\xim\web\controllers\FileUpload\FileUpload.java * @Description: 用于接受上传文件的Controller。 * @@ -24,6 +24,13 @@ import org.springframework.web.multipart.MultipartFile; @RequestMapping( path = "/file" ) public class FileUpload { + /***************************************************** + * 接收上传文件,并保存到临时目录: + * 1、临时目录下再用sessionID作为子目录保存文件。 + * 2、保存时不更改文件名,会覆盖同名文件。 + * 3、MultipartFile参数形参名称必须和请求form中file标签的name属性一致,否则值为null。 + * 4、返回值为接收结果和文件保存路径。 + *****************************************************/ @RequestMapping( path = "/file-upload.do" ) @ResponseBody public FileUploadResult getUploadFile( @RequestParam( "task-name" ) String taskName, @@ -35,10 +42,13 @@ public class FileUpload Vector fileNames = new Vector(); int fileCount = files.length; + // 防御验证 if ( files.length == 0 ) { result.setSuccess( false ); result.setMessage( "此接口用于上传文件!" ); + + return result; } result.setSuccess( true ); @@ -46,9 +56,17 @@ public class FileUpload for ( MultipartFile file : files ) { - String fileName = file.getName(); + if ( file.isEmpty() ) + { + // 文件长度位0,跳过 + continue; + } - fileNames.add( fileName ); + String filePath = + request.getServletContext().getRealPath( "/temp/upload/" + sessionID ); + String fileName = file.getOriginalFilename(); + + fileNames.add( file.getOriginalFilename() ); } result.setFileList( fileNames ); diff --git a/企业级管理系统/java/AdminSys/src/main/java/com/cpic/xim/web/filters/token/TokenFilter.java b/企业级管理系统/java/AdminSys/src/main/java/com/cpic/xim/web/filters/token/TokenFilter.java index dea62f8..40aab79 100644 --- a/企业级管理系统/java/AdminSys/src/main/java/com/cpic/xim/web/filters/token/TokenFilter.java +++ b/企业级管理系统/java/AdminSys/src/main/java/com/cpic/xim/web/filters/token/TokenFilter.java @@ -2,7 +2,7 @@ * @Author: Kane * @Date: 2023-01-12 15:01:22 * @LastEditors: Kane - * @LastEditTime: 2023-01-24 00:07:36 + * @LastEditTime: 2023-01-24 00:21:51 * @FilePath: \AdminSys\src\main\java\com\cpic\xim\web\filters\token\TokenFilter.java * @Description: 用于检查token的过滤器 * @@ -23,7 +23,7 @@ import javax.servlet.http.HttpServletResponse; public class TokenFilter implements Filter { /***************************************************** - * + * 对请求的token进行验证。 *****************************************************/ @Override public void doFilter( ServletRequest req, ServletResponse resp, FilterChain chain )