fileupload上传文件

来源:互联网 发布:最新滤镜软件 编辑:程序博客网 时间:2024/06/04 19:24

jar包commons-fileupload-1.3.1.jar
首先配置文件servlet中要加上

<mvc:default-servlet-handler />    <!-- 实现SpringMVC的注解驱动 -->    <mvc:annotation-driven/>    <!-- 用于文件上传 设置最大支持200M-->    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"        p:defaultEncoding="UTF-8"        p:maxUploadSize="209715200"/><!-- 单位是字节 --></beans>
//上传文件    @RequestMapping("/uploadPdf")    @ResponseBody    public  String uploadPdf(@RequestParam("file") MultipartFile file)throws IllegalStateException, IOException{        String type = file.getContentType();        if (!type.contains("pdf")) {            return  "type error";        }        String tomcatPath = this.getClass().getClassLoader().getResource("/")                .getPath();        String uploadPath = tomcatPath.substring(1,tomcatPath.length()-16) +"uploadFiles/"+file.getOriginalFilename();//            String uploadPath = "D:\\MyEclipseWorkspaces\\JCI\\WebRoot\\uploadFiles\\"+file.getOriginalFilename();;//        System.out.println("-----"+uploadPath);        if(!file.isEmpty()){            file.transferTo(new File(uploadPath));            uploadPdfBiz.analysisPdf(uploadPath);            return  "success";        }else{            return  "file empty";        }    }
0 0
原创粉丝点击