- 浏览: 851358 次
文章分类
- 全部博客 (365)
- java (124)
- spring mvc (21)
- spring (22)
- struts2 (6)
- jquery (27)
- javascript (24)
- mybatis/ibatis (8)
- hibernate (7)
- compass (11)
- lucene (26)
- flex (0)
- actionscript (0)
- webservice (8)
- rabbitMQ/Socket (15)
- jsp/freemaker (5)
- 数据库 (27)
- 应用服务器 (21)
- Hadoop (1)
- PowerDesigner (3)
- EJB (0)
- JPA (0)
- PHP (2)
- C# (0)
- .NET (0)
- html (2)
- xml (5)
- android (7)
- flume (1)
- zookeeper (0)
- 证书加密 (2)
- maven (1)
- redis (2)
- cas (11)
最新评论
-
zuxianghuang:
通过pom上传报错 Artifact upload faile ...
nexus上传了jar包.通过maven引用当前jar,不能取得jar的依赖 -
流年末年:
百度网盘的挂了吧???
SSO单点登录系列3:cas-server端配置认证方式实践(数据源+自定义java类认证) -
953434367:
UfgovDBUtil 是什么类
Java发HTTP POST请求(内容为xml格式) -
smilease:
帮大忙了,非常感谢
freemaker自动生成源代码 -
syd505:
十分感谢作者无私的分享,仔细阅读后很多地方得以解惑。
Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解
参照了网上相关代码
注意事项:
1 springmvc.xml必须配置:
注意事项:
1 springmvc.xml必须配置:
- <bean id="multipartResolver"
- class="org.springframework.web.multipart.commons.CommonsMultipartResolver" p:defaultEncoding="utf-8"/>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" p:defaultEncoding="utf-8"/>
2 WEB-INF/lib下必加入:commons-fileupload.jar与commons-io-1.4.jar二个文件
3 表单属性为: enctype="multipart/form-data"
工程项目图片如下:
具体代码如下:
FileUploadBean.java
- public class FileUploadBean {
- private byte[] file;
- public void setFile(byte[] file) {
- this.file = file;
- }
- public byte[] getFile() {
- return file;
- }
- }
public class FileUploadBean { private byte[] file; public void setFile(byte[] file) { this.file = file; } public byte[] getFile() { return file; } }
- package net.liuzd.web;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.net.BindException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.springframework.stereotype.Controller;
- import org.springframework.util.FileCopyUtils;
- import org.springframework.web.bind.annotation.PathVariable;
- 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.multipart.MultipartFile;
- import org.springframework.web.multipart.MultipartHttpServletRequest;
- import org.springframework.web.multipart.commons.CommonsMultipartFile;
- import org.springframework.web.servlet.ModelAndView;
- /**
- * Title: Description: Copyright: Copyright (c) 2011
- * Company:http://liuzidong.iteye.com/ Makedate:2011-5-27 下午01:52:17
- *
- * @author liuzidong
- * @version 1.0
- * @since 1.0
- *
- */
- @Controller
- public class FileUploadController {
- @RequestMapping(value = "/upload", method = RequestMethod.POST)
- public ModelAndView onSubmit(HttpServletRequest request,
- HttpServletResponse response, BindException errors)
- throws Exception {
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- CommonsMultipartFile file = (CommonsMultipartFile) multipartRequest
- .getFile("file");
- String name = multipartRequest.getParameter("name");
- System.out.println("name: " + name);
- // 获得文件名:
- String realFileName = file.getOriginalFilename();
- System.out.println("获得文件名:" + realFileName);
- // 获取路径
- String ctxPath = request.getSession().getServletContext().getRealPath(
- "/")
- + "images/";
- // 创建文件
- File dirPath = new File(ctxPath);
- if (!dirPath.exists()) {
- dirPath.mkdir();
- }
- File uploadFile = new File(ctxPath + realFileName);
- FileCopyUtils.copy(file.getBytes(), uploadFile);
- request.setAttribute("files", loadFiles(request));
- return new ModelAndView("success");
- }
- @RequestMapping(value = "/upload2", method = RequestMethod.POST)
- public ModelAndView onSubmit2(HttpServletRequest request,
- HttpServletResponse response, BindException errors)
- throws Exception {
- // 转型为MultipartHttpRequest
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- // 根据前台的name名称得到上传的文件
- MultipartFile file = multipartRequest.getFile("file");
- // 获得文件名:
- String realFileName = file.getOriginalFilename();
- // 获取路径
- String ctxPath = request.getSession().getServletContext().getRealPath(
- "/")
- + "\\" + "images\\";
- // 创建文件
- File dirPath = new File(ctxPath);
- if (!dirPath.exists()) {
- dirPath.mkdir();
- }
- File uploadFile = new File(ctxPath + realFileName);
- FileCopyUtils.copy(file.getBytes(), uploadFile);
- request.setAttribute("files", loadFiles(request));
- return new ModelAndView("success");
- }
- @RequestMapping(value = "/upload3", method = RequestMethod.POST)
- public String upload(@RequestParam("file")
- MultipartFile image, HttpServletRequest request) throws IOException {
- String ctxPath = request.getSession().getServletContext().getRealPath(
- "/")
- + "\\" + "images\\";
- System.out.println("路径:" + ctxPath);
- File file = new File(ctxPath + "/" + image.getOriginalFilename());
- // FileCopyUtils.copy(image.getBytes(),new
- // File(ctxPath+"/"+image.getOriginalFilename()));
- try {
- image.transferTo(file); // 保存上传的文件
- } catch (IllegalStateException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- request.setAttribute("files", loadFiles(request));
- return "success";
- }
- // 多文件上传
- @RequestMapping(value = "/upload4", method = RequestMethod.POST)
- public ModelAndView fileUpload(HttpServletRequest request,
- HttpServletResponse response, BindException errors)
- throws Exception {
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
- String ctxPath = request.getSession().getServletContext().getRealPath(
- "/")
- + "\\" + "images\\";
- File file = new File(ctxPath);
- if (!file.exists()) {
- file.mkdir();
- }
- String fileName = null;
- for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
- // 上传文件名
- // System.out.println("key: " + entity.getKey());
- MultipartFile mf = entity.getValue();
- fileName = mf.getOriginalFilename();
- File uploadFile = new File(ctxPath + fileName);
- FileCopyUtils.copy(mf.getBytes(), uploadFile);
- }
- request.setAttribute("files", loadFiles(request));
- return new ModelAndView("success");
- }
- // @ModelAttribute("files")//此属性用于初始类时调用,但上传文件后不能时时反应上传文件个数,不适合动态数据
- public List<String> loadFiles(HttpServletRequest request) {
- List<String> files = new ArrayList<String>();
- String ctxPath = request.getSession().getServletContext().getRealPath(
- "/")
- + "\\" + "images\\";
- File file = new File(ctxPath);
- if (file.exists()) {
- File[] fs = file.listFiles();
- String fname = null;
- for (File f : fs) {
- fname = f.getName();
- if (f.isFile()) {
- files.add(fname);
- }
- }
- }
- return files;
- }
- @RequestMapping("/download/{fileName}")
- public ModelAndView download(@PathVariable("fileName")
- String fileName, HttpServletRequest request, HttpServletResponse response)
- throws Exception {
- response.setContentType("text/html;charset=utf-8");
- request.setCharacterEncoding("UTF-8");
- java.io.BufferedInputStream bis = null;
- java.io.BufferedOutputStream bos = null;
- String ctxPath = request.getSession().getServletContext().getRealPath(
- "/")
- + "\\" + "images\\";
- String downLoadPath = ctxPath + fileName;
- System.out.println(downLoadPath);
- try {
- long fileLength = new File(downLoadPath).length();
- response.setContentType("application/x-msdownload;");
- response.setHeader("Content-disposition", "attachment; filename="
- + new String(fileName.getBytes("utf-8"), "ISO8859-1"));
- response.setHeader("Content-Length", String.valueOf(fileLength));
- bis = new BufferedInputStream(new FileInputStream(downLoadPath));
- bos = new BufferedOutputStream(response.getOutputStream());
- byte[] buff = new byte[2048];
- int bytesRead;
- while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
- bos.write(buff, 0, bytesRead);
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (bis != null)
- bis.close();
- if (bos != null)
- bos.close();
- }
- return null;
- }
- }
package net.liuzd.web; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.net.BindException; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.util.FileCopyUtils; import org.springframework.web.bind.annotation.PathVariable; 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.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.commons.CommonsMultipartFile; import org.springframework.web.servlet.ModelAndView; /** * Title: Description: Copyright: Copyright (c) 2011 * Company:http://liuzidong.iteye.com/ Makedate:2011-5-27 下午01:52:17 * * @author liuzidong * @version 1.0 * @since 1.0 * */ @Controller public class FileUploadController { @RequestMapping(value = "/upload", method = RequestMethod.POST) public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; CommonsMultipartFile file = (CommonsMultipartFile) multipartRequest .getFile("file"); String name = multipartRequest.getParameter("name"); System.out.println("name: " + name); // 获得文件名: String realFileName = file.getOriginalFilename(); System.out.println("获得文件名:" + realFileName); // 获取路径 String ctxPath = request.getSession().getServletContext().getRealPath( "/") + "images/"; // 创建文件 File dirPath = new File(ctxPath); if (!dirPath.exists()) { dirPath.mkdir(); } File uploadFile = new File(ctxPath + realFileName); FileCopyUtils.copy(file.getBytes(), uploadFile); request.setAttribute("files", loadFiles(request)); return new ModelAndView("success"); } @RequestMapping(value = "/upload2", method = RequestMethod.POST) public ModelAndView onSubmit2(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { // 转型为MultipartHttpRequest MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; // 根据前台的name名称得到上传的文件 MultipartFile file = multipartRequest.getFile("file"); // 获得文件名: String realFileName = file.getOriginalFilename(); // 获取路径 String ctxPath = request.getSession().getServletContext().getRealPath( "/") + "\\" + "images\\"; // 创建文件 File dirPath = new File(ctxPath); if (!dirPath.exists()) { dirPath.mkdir(); } File uploadFile = new File(ctxPath + realFileName); FileCopyUtils.copy(file.getBytes(), uploadFile); request.setAttribute("files", loadFiles(request)); return new ModelAndView("success"); } @RequestMapping(value = "/upload3", method = RequestMethod.POST) public String upload(@RequestParam("file") MultipartFile image, HttpServletRequest request) throws IOException { String ctxPath = request.getSession().getServletContext().getRealPath( "/") + "\\" + "images\\"; System.out.println("路径:" + ctxPath); File file = new File(ctxPath + "/" + image.getOriginalFilename()); // FileCopyUtils.copy(image.getBytes(),new // File(ctxPath+"/"+image.getOriginalFilename())); try { image.transferTo(file); // 保存上传的文件 } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } request.setAttribute("files", loadFiles(request)); return "success"; } // 多文件上传 @RequestMapping(value = "/upload4", method = RequestMethod.POST) public ModelAndView fileUpload(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); String ctxPath = request.getSession().getServletContext().getRealPath( "/") + "\\" + "images\\"; File file = new File(ctxPath); if (!file.exists()) { file.mkdir(); } String fileName = null; for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { // 上传文件名 // System.out.println("key: " + entity.getKey()); MultipartFile mf = entity.getValue(); fileName = mf.getOriginalFilename(); File uploadFile = new File(ctxPath + fileName); FileCopyUtils.copy(mf.getBytes(), uploadFile); } request.setAttribute("files", loadFiles(request)); return new ModelAndView("success"); } // @ModelAttribute("files")//此属性用于初始类时调用,但上传文件后不能时时反应上传文件个数,不适合动态数据 public List<String> loadFiles(HttpServletRequest request) { List<String> files = new ArrayList<String>(); String ctxPath = request.getSession().getServletContext().getRealPath( "/") + "\\" + "images\\"; File file = new File(ctxPath); if (file.exists()) { File[] fs = file.listFiles(); String fname = null; for (File f : fs) { fname = f.getName(); if (f.isFile()) { files.add(fname); } } } return files; } @RequestMapping("/download/{fileName}") public ModelAndView download(@PathVariable("fileName") String fileName, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/html;charset=utf-8"); request.setCharacterEncoding("UTF-8"); java.io.BufferedInputStream bis = null; java.io.BufferedOutputStream bos = null; String ctxPath = request.getSession().getServletContext().getRealPath( "/") + "\\" + "images\\"; String downLoadPath = ctxPath + fileName; System.out.println(downLoadPath); try { long fileLength = new File(downLoadPath).length(); response.setContentType("application/x-msdownload;"); response.setHeader("Content-disposition", "attachment; filename=" + new String(fileName.getBytes("utf-8"), "ISO8859-1")); response.setHeader("Content-Length", String.valueOf(fileLength)); bis = new BufferedInputStream(new FileInputStream(downLoadPath)); bos = new BufferedOutputStream(response.getOutputStream()); byte[] buff = new byte[2048]; int bytesRead; while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) { bos.write(buff, 0, bytesRead); } } catch (Exception e) { e.printStackTrace(); } finally { if (bis != null) bis.close(); if (bos != null) bos.close(); } return null; } }
spring.xml
- <?xml version="1.0" encoding="UTF-8" ?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:p="http://www.springframework.org/schema/p"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd">
- <!--
- 自动搜索@Controller标注的类
- 用于指明系统从哪个路径下寻找controller,然后提前初始化这些对象。
- -->
- <context:component-scan base-package="net.liuzd.web" />
- <!-- ③:对模型视图名称的解析,即在模型视图名称添加前后缀 -->
- <bean
- class="org.springframework.web.servlet.view.InternalResourceViewResolver"
- p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
- <bean id="multipartResolver"
- class="org.springframework.web.multipart.commons.CommonsMultipartResolver" p:defaultEncoding="utf-8">
- <property name="maxUploadSize">
- <value>104857600</value>
- </property>
- <property name="maxInMemorySize">
- <value>4096</value>
- </property>
- </bean>
- </beans>
<?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- 自动搜索@Controller标注的类 用于指明系统从哪个路径下寻找controller,然后提前初始化这些对象。 --> <context:component-scan base-package="net.liuzd.web" /> <!-- ③:对模型视图名称的解析,即在模型视图名称添加前后缀 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" p:defaultEncoding="utf-8"> <property name="maxUploadSize"> <value>104857600</value> </property> <property name="maxInMemorySize"> <value>4096</value> </property> </bean> </beans>
success.jsp
- <%@ taglib prefix="c" uri="/WEB-INF/c.tld"%>
- <h1>Upload Successful</h1>
- <c:forEach var="month" items="${files}">
- <li><a href="${pageContext.request.contextPath}/download/${month}.do">${month}</a></li>
- </c:forEach>
- <hr><br>
- <a href="${pageContext.request.contextPath}/index.jsp">返回</a>
<%@ taglib prefix="c" uri="/WEB-INF/c.tld"%> <h1>Upload Successful</h1> <c:forEach var="month" items="${files}"> <li><a href="${pageContext.request.contextPath}/download/${month}.do">${month}</a></li> </c:forEach> <hr><br> <a href="${pageContext.request.contextPath}/index.jsp">返回</a>
web.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
- http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
- <context-param>
- <param-name>log4jConfigLocation</param-name>
- <param-value>/WEB-INF/classes/log4j.properties</param-value>
- </context-param>
- <context-param>
- <param-name>log4jRefreshInterval</param-name>
- <param-value>60000</param-value>
- </context-param>
- <context-param>
- <param-name>log4jExposeWebAppRoot</param-name>
- <param-value>false</param-value>
- </context-param>
- <listener>
- <listener-class>
- org.springframework.web.util.Log4jConfigListener
- </listener-class>
- </listener>
- <filter>
- <filter-name>encodingFilter</filter-name>
- <filter-class>
- org.springframework.web.filter.CharacterEncodingFilter
- </filter-class>
- <init-param>
- <param-name>encoding</param-name>
- <param-value>UTF-8</param-value>
- </init-param>
- <init-param>
- <param-name>forceEncoding</param-name>
- <param-value>false</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>encodingFilter</filter-name>
- <url-pattern>*.do</url-pattern>
- </filter-mapping>
- <filter-mapping>
- <filter-name>encodingFilter</filter-name>
- <url-pattern>*.jsp</url-pattern>
- </filter-mapping>
- <servlet>
- <servlet-name>springmvc</servlet-name>
- <servlet-class>
- org.springframework.web.servlet.DispatcherServlet
- </servlet-class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:springmvc.xml</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>springmvc</servlet-name>
- <url-pattern>*.do</url-pattern>
- </servlet-mapping>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
评论
5 楼
2047699523
2015-05-19
spring mvc demo教程源代码下载:http://www.zuidaima.com/share/kspringmvc-p1-s1.htm
4 楼
yuechen323
2015-03-15
代码写了2次,而且还这么啰嗦
3 楼
lemoCC
2015-02-03
- [list]
- [*][list]
- [*][*][list]
- [*][*][*]
- [*][*]
2 楼
lemoCC
2015-02-03
[flash=200,200][flash=200,200][url][img][list] |
[*]
|
[/list][/img][/url][/flash][/flash] |
1 楼
tonyyouwei
2013-11-30
写的真好!
发表评论
-
jackson annotations注解详解
2015-01-13 11:34 18991官方WIKI:https://github.com/Fast ... -
Ehcache 整合Spring 使用页面、对象缓存
2012-11-02 19:56 1098Ehcache在很多项目中都出现过,用法也比较简 ... -
Spring 3.1 M1 中的缓存功能
2012-11-02 19:26 825本文转自:http://www.oschina.net/ ... -
深入剖析Spring Web源码(八) - 处理器映射,处理器适配器以及处理器的实现 - 基于简单控制器流程的实现
2012-10-31 13:37 13121.1.1.1 ... -
spring 源码 阅读 笔记 之 HandlerMapping
2012-10-31 12:59 1670SpringCVSBeanHTMLAnt ... -
spring mvc重复提交拦截器方法
2012-10-31 11:37 9009import javax.servlet.http.HttpS ... -
不重复配置——利用Spring通用化配置
2012-10-17 09:40 975还记得 如下这种配置吗: 1、struts2作用域 ... -
Ehcache 整合Spring 使用页面、对象缓存
2012-10-16 09:44 784Ehcache在很多项目中都出现过,用法也比较简单。一般的 ... -
SpringMVC文件上传 多文件
2012-10-15 17:27 7082必须明确告诉DispatcherServlet如何处理Mult ... -
Spring MVC 3.1新特性 生产者、消费者请求限定
2012-10-12 11:50 11446.6.5、生产者、消费者限定 6.6.5.1、基本概念 ... -
spring + mybatis 多数据源切换
2012-10-10 11:42 1558[代码] DbContextHold ... -
spring MVC 文件上传
2012-10-06 10:03 2068spring支持在网络应用程序处理文件上传,提供拔插的org. ... -
JasperReport与spring集成的三种方式
2012-09-26 17:29 1853最近要用JasperReport,试着和sprin ... -
Spring MVC+Jasper Report 及生成PDF的中文问题
2012-09-26 17:10 2先说两句报表框架的选择,JasperRepor ... -
Springmvc与jasperreport结合生成报表的一种方法
2012-09-26 16:42 1<script type="text/ja ... -
spring 3.1中的cache小结
2012-09-22 23:27 1008spring 3.1中有cache了,下 ... -
Spring MVC和Struts2的区别
2012-09-08 08:59 10361. 机制:spring mvc的入口是servlet,而st ... -
SpringMVC + spring3.1.1 + hibernate4.1.0 集成及常见问题总结
2012-06-19 17:34 1418一 开发环境 1、动态web工程 2、部分依赖 ... -
用spring MVC 生成Excel和PDF
2012-06-16 19:16 36301 用spring MVC 生成Excel和PDF http ... -
SpringMVC+FreeMarker实现半自动静态化
2012-06-14 13:53 2532感谢imyourgod的原贴http://to ...
相关推荐
在SpringMVC框架中,实现文件的上传与下载是常见的需求。IntelliJ IDEA作为流行的Java开发集成环境,为开发者提供了高效便捷的开发体验。在这个项目中,我们使用IDEA来构建一个基于SpringMVC的系统,实现了文件的...
基于springmvc实现文件上传下载 基于AOP的日志功能基于springmvc实现文件上传下载 基于AOP的日志功能基于springmvc实现文件上传下载 基于AOP的日志功能基于springmvc实现文件上传下载 基于AOP的日志功能基于...
在Spring MVC框架中,文件上传和下载是常见的功能需求,特别是在构建Web应用程序时。下面将详细阐述Spring MVC中实现文件上传和下载的关键知识点,并提供相关的jar包和案例资源。 一、文件上传 1. **依赖引入**:...
在Spring MVC框架中,文件上传和下载是常见的需求,尤其在构建Web应用程序时。下面将详细阐述如何使用Spring MVC实现这些功能,以及如何添加文件压缩的特性。 首先,我们需要了解Spring MVC中的MultipartFile接口,...
在SpringMVC框架中,文件上传与下载是常见的功能需求,尤其在开发Web应用时,用户可能需要上传图片、文档等文件,或者从服务器下载资源。本教程将深入讲解SpringMVC如何处理文件上传和下载操作,并通过源码分析来...
在这个主题“springMVC的上传与下载”中,我们将深入探讨如何在 Spring MVC 中实现文件上传和下载功能。 **文件上传** 1. **配置 Spring MVC**: 首先,你需要在 `web.xml` 文件中配置 DispatcherServlet 和 Spring...
SpringMVC提供MultipartFile接口处理文件上传,而文件下载则可以通过StreamingResponseBody或者直接返回文件路径实现。这些功能的实现涉及了流处理和响应头设置,确保了文件传输的正确性和效率。 异常处理在Web应用...
SpringMVC文件上传与下载的实现,实际开发过程中由于使用的Spring版本比较低的,所以一些最新的注解以及方法不能使用,然后使用了一些替代的方法,另外在项目中使用到的路径是从内存中读取的并不是项目路径,具体的...
在这个整合包中,我们还将探讨如何结合Bootstrap来实现前端界面的快速开发,并学习文件上传与下载的功能。 1. **Spring框架**:Spring是Java企业级应用的核心框架,它提供了依赖注入(DI)和面向切面编程(AOP)等...
本文档主要介绍了SpringMVC的ModelAndView机制,使用SpringMVC实现文件上传,下载以及全局异常处理机制
本文主要目的是记录自己基于SpringMVC实现的文件上传和下载的工具类的编写,代码经过测试可以直接运行在以后的项目中。开发的主要思路是对上传和下载文件进行抽象,把上传和下载的核心功能抽取出来分装成类。
在Spring MVC框架中,文件上传和下载是常见的功能需求,涉及到服务器与客户端的数据交互。本压缩包提供的资源包括了实现这些功能所必需的关键组件。以下是关于这些组件的详细解释: 1. **Spring MVC**:Spring MVC...
在`spring-servlet.xml`中,你需要声明`<mvc:annotation-driven>`来启用对注解驱动的控制器的支持,这将自动配置处理上传和下载所需的组件。 2. **上传文件** - **Controller**:在控制器类中,你可以使用`@...
在Spring MVC框架中实现文件上传并提供进度条功能是一项实用且复杂的任务,涉及到前端与后端的交互以及数据传输过程的监控。以下是对这个主题的详细解析。 首先,我们需要理解Spring MVC的基本工作原理。Spring MVC...
在Spring MVC框架中,文件上传和下载是常见的功能需求,特别是在构建Web应用程序时。这篇博客文章详细介绍了如何在Spring MVC项目中实现这两个操作。以下是对这些知识点的详细说明: 1. **Spring MVC简介** Spring...
SpringMVC提供了便捷的文件上传支持,通过`@RequestParam("file") MultipartFile file`注解接收文件,并且可以处理文件的保存和下载操作。这涉及到文件流的读写以及文件存储策略。 异常处理是任何应用程序都需要...
本实验报告将详细阐述如何利用SpringMVC实现文件上传与下载的功能。 首先,文件上传的核心在于HTML表单(form)的正确配置。在创建用于上传文件的表单时,需要指定`enctype`属性为`multipart/form-data`。这是因为...
在Spring MVC框架中,文件的上传与下载是常见的功能需求,尤其在Web应用中不可或缺。本文将详细讲解如何实现Spring MVC中的文件上传和下载,包括单一文件上传、多文件上传以及两种不同的文件下载方法。 一、单一...
本教程将深入讲解如何利用SpringMVC实现文件上传和下载功能,以及如何实现应用的国际化。下面我们将详细探讨这些知识点。 **一、SpringMVC文件上传** 在SpringMVC中,文件上传主要依赖于`CommonsMultipartResolver...
文件上传是项目开发中最常见的功能。为了能上传文件,必须将表单的method设置为POST,并将enctype设置为multipart/form-data。只有在这样的情况下,浏览器才会把用户选择的文件以二进制数据发送给服务器。 一旦设置...