使用SringMvc完成文件和图片上传功能
来源:互联网 发布:达内java简历模板 编辑:程序博客网 时间:2024/06/06 03:06
使用SringMvc完成文件和图片上传功能
完成功能:
- 文件上传
- 图片上传
- 多张图片上传
先下载我们使用spring注解所需要的jar包[springmvc 注解版 jar包](http://download.csdn.net/detail/u010782846/9676654)[commons-fileupload-1.2.2](http://download.csdn.net/detail/zhongjie_js/3303830) 先配置WebContent/WEB-INF/web.xml
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:beans.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 配置spring dispatcherServlet --> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 通过初始化参数指定xml配置位置 --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
在src/文件夹下 新建两个xml文件
**springmvc.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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd "> <!-- 内部资源视图解析器 --> <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean></beans
**beans.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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd "> <!-- 扫描组件 --> <context:component-scan base-package="cn.itcast.srpingmvc"></context:component-scan> <!-- 注解驱动 --> <mvc:annotation-driven /> <!-- SpringMVC上传文件时,需要配置MultipartResolver处理器 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <!-- 指定所上传文件的总大小不能超过200KB。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 --> <!-- one of the properties available; the maximum file size in bytes --> <property name="maxUploadSize" value="200000" /> </bean></beans>
以上我们就配置好了基础配置,我们先来完成 简单的 单一文件进行表单的上传:
流程如下 :
FileUploadController 中的public String SingleFileUploadUI()–>跳转到 fileform.jsp –>选好文件后 跳转到FileUploadController 中的public String SingleFileUpload方法,
未完 待续。。。。。。
0 0
- 使用SringMvc完成文件和图片上传功能
- 完成文件的上传和删除功能
- java完成文件上传功能
- 实现图片上传预览和取消文件上传功能
- 点击图片就可以完成上传功能
- 如何用 React 完成图片上传功能
- Struts2完成文件的上传功能实例
- 使用FTP命令自动完成文件的上传和下载
- 单个文件(图片)上传功能
- 文件上传插件Plupload使用(带图片预览功能)
- 使用Ckeditor+Ckfinder完成图片上传
- JAVA使用apache commons-fileupload组件完成文件上传到服务器功能
- struts2结合uploadify-v3.1完成批量图片上传功能
- 使用apache开源包完成文件上传
- 使用Spring MVC 完成文件的上传
- 自动上传本地图片和word图片(word图片需使用从word粘贴功能)
- MVC5:使用Ajax和HTML5实现文件上传功能
- JSP+Servlet使用commons.fileupload和commons.io完成图片上传
- Linux C——网络编程基础知识
- 文件加解密操作
- 关于Android6.0系统动态权限管理的解决方案
- 形形色色的Linux 发行版代号都在这里
- 动态bean生成
- 使用SringMvc完成文件和图片上传功能
- STL优先队列priority_queue用法详解
- Django学习总结一:models的字段说明
- 集合(collection API)
- CF - 269B LIS
- Ubuntu 秘笈之命令行下管理浏览器书签
- uva 11806 Cheerleaders 容斥原理+组合数
- Java基础1
- 一旦开始,就应该坚持下来