• 大小: 19.53MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-07-21
  • 语言: 其他
  • 标签: javaweb  

资源简介

亲测好用的ssm框架下文件下载,上传,将数据保存在tomcat服务器。

资源截图

代码片段和文件信息

package com.core.controller;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
/**
 * 下载  测试
 * @author 王一土
 *
 */
@Controller
@RequestMapping(“UploadController“)
public class UploadController {

    @RequestMapping(value=“/upload“method=RequestMethod.POST)
    @ResponseBody  
    public String upload(@RequestParam MultipartFile fileHttpServletRequest request) throws IOException{  
     String path = System.getProperty(“catalina.home“) + “/webapps/fileOperation/upload/“;
        String fileName = file.getOriginalFilename();    
        File dir = new File(pathfileName);          
        if(!dir.exists()){  
            dir.mkdirs();  
        }  
        file.transferTo(dir);  
        return fileName;  
    }  
    
       @RequestMapping(“/down“)  
        public void down(
         @RequestParam String filename
         HttpServletRequest requestHttpServletResponse response) throws Exception{  
           
        if(filename!=““ && !filename.equals(““)) {
            String fileName = System.getProperty(“catalina.home“) + “/webapps/fileOperation/upload/“+filename;  
               
               InputStream bis = new BufferedInputStream(new FileInputStream(new File(fileName)));  

               filename = URLEncoder.encode(filename“UTF-8“);  
               
               response.addHeader(“Content-Disposition“ “attachment;filename=“ + filename);    
                   
               response.setContentType(“multipart/form-data“);   
               
               BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());  
               int len = 0;  
               while((len = bis.read()) != -1){  
                   out.write(len);  
                   out.flush();  
               }  
               out.close();
           }else {
             request.getSession().setAttribute(“result“ “文件名为空!“);;
           }
        }  
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        836  2018-11-09 08:58  fileOperation\.classpath

     文件        913  2018-11-09 08:58  fileOperation\.project

     文件        567  2018-11-09 08:58  fileOperation\.settings\.jsdtscope

     文件        364  2018-11-09 08:58  fileOperation\.settings\org.eclipse.jdt.core.prefs

     文件        491  2018-11-09 08:58  fileOperation\.settings\org.eclipse.wst.common.component

     文件        345  2018-11-09 08:58  fileOperation\.settings\org.eclipse.wst.common.project.facet.core.xml

     文件         49  2018-11-09 08:58  fileOperation\.settings\org.eclipse.wst.jsdt.ui.superType.container

     文件          6  2018-11-09 08:58  fileOperation\.settings\org.eclipse.wst.jsdt.ui.superType.name

     文件        854  2018-11-08 19:02  fileOperation\build\classes\applicationContext.xml

     文件       3690  2018-11-20 16:09  fileOperation\build\classes\com\core\controller\UploadController.class

     文件       1121  2018-11-08 19:39  fileOperation\build\classes\spring-mvc.xml

     文件        854  2018-11-08 19:02  fileOperation\src\applicationContext.xml

     文件       2595  2018-11-20 16:09  fileOperation\src\com\core\controller\UploadController.java

     文件       1121  2018-11-08 19:39  fileOperation\src\spring-mvc.xml

     文件     128529  2018-10-30 10:14  fileOperation\WebContent\js\jquery.min.js

     文件         39  2018-11-09 08:58  fileOperation\WebContent\meta-INF\MANIFEST.MF

     文件       1766  2018-11-20 16:13  fileOperation\WebContent\upload.jsp

     文件      43578  2018-05-25 10:37  fileOperation\WebContent\WEB-INF\lib\asm-3.3.jar

     文件      38275  2018-05-25 10:37  fileOperation\WebContent\WEB-INF\lib\asm-commons-3.3.jar

     文件      21503  2018-05-25 10:37  fileOperation\WebContent\WEB-INF\lib\asm-tree-3.3.jar

     文件    1569376  2018-06-13 10:03  fileOperation\WebContent\WEB-INF\lib\bcprov-jdk15-138.jar

     文件    1876535  2016-03-21 14:08  fileOperation\WebContent\WEB-INF\lib\bcprov-jdk16-1.46.jar

     文件     608376  2018-05-25 10:37  fileOperation\WebContent\WEB-INF\lib\c3p0-0.9.1.jar

     文件     326877  2018-05-25 10:37  fileOperation\WebContent\WEB-INF\lib\com.springsource.net.sf.cglib-2.2.0.jar

     文件       4615  2018-05-25 10:37  fileOperation\WebContent\WEB-INF\lib\com.springsource.org.aopalliance-1.0.0.jar

     文件    1642154  2018-05-25 10:37  fileOperation\WebContent\WEB-INF\lib\com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar

     文件     231320  2018-05-25 10:37  fileOperation\WebContent\WEB-INF\lib\commons-beanutils-1.8.0.jar

     文件     263965  2018-05-25 10:37  fileOperation\WebContent\WEB-INF\lib\commons-codec-1.9.jar

     文件     559366  2018-05-25 10:37  fileOperation\WebContent\WEB-INF\lib\commons-collections-3.1.jar

     文件     148817  2018-05-25 10:37  fileOperation\WebContent\WEB-INF\lib\commons-dbcp-1.3.jar

............此处省略68个文件信息

评论

共有 条评论