Using a MultipartResolver with Commons FileUpload[就是使用commons FileUpload上传文件]
来源:互联网 发布:新手护肤步骤知乎 编辑:程序博客网 时间:2024/05/01 14:16
依照文档中做的起始就是需要配置一下和倒下包就行了。
当然在我们上传文件的时候我们是使用spring 和commonsFileUpLoad的集成的文件上传解析器MultipartResolver
为什么使用它呢?其实也是为了我们 在spring中能够使用到他,因为spring其实也没有做什么,就是将这个类做了这么一步、
CommonsMultipartResolver extends CommonsFileUploadSupport
implements MultipartResolver,ServletContextAware
看到没,其实就是做了一下spring和commonsFile的支持,继承了CommonsFileUploadSupport类
和实现ServletContextAware类
闲话不多说,在xml中的配置如下:
1
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <!-- one of the properties available; the maximum file size in bytes --> <property name="maxUploadSize" value="100000"/>//这是 byte</bean>
2
当然就是导入我们的commons-fileupload.jar。
但是我们没这个jar的,但是幸好我用struts2,那么我们可以找到,但是我们需要导人两个,
一个是commons-fileupload-**.jar和commons-io-**.jar{**指的是版本号}
3(直接拷官方文档)
16.9.4 Handling a file upload in a form
After the MultipartResolver
completes its job, the request is processed like any other. First, create a form with a file input that will allow the user to upload a form. The encoding attribute (enctype="multipart/form-data"
) lets the browser know how to encode the form as multipart request:
<html> <head> <title>Upload a file please</title> </head> <body> <h1>Please upload a file</h1> <form method="post" action="/form" enctype="multipart/form-data"> <input type="text" name="name"/> <input type="file" name="file"/> <input type="submit"/> </form> </body></html>
The next step is to create a controller that handles the file upload. This controller is very similar to a normal annotated @Controller
, except that we use MultipartHttpServletRequest
or MultipartFile
in the method parameters:
@Controllerpublic class FileUpoadController { @RequestMapping(value = "/form", method = RequestMethod.POST) public String handleFormUpload(@RequestParam("name") String name, @RequestParam("file") MultipartFile file) { if (!file.isEmpty()) { byte[] bytes = file.getBytes(); // store the bytes somewhere return "redirect:uploadSuccess"; } else { return "redirect:uploadFailure"; } }}
- Using a MultipartResolver with Commons FileUpload[就是使用commons FileUpload上传文件]
- 使用commons fileupload 上传文件
- 使用 Commons-fileupload 上传文件
- 使用commons-fileupload上传文件
- 使用 Commons-fileupload 上传文件
- 文件上传 using org.apache.commons.fileupload
- 文件上传 commons-FileUpload
- Commons FileUpload上传文件
- Commons FileUpload上传文件
- commons-fileupload-文件上传
- commons fileupload 文件上传
- commons-fileupload上传文件
- 文件上传 commons-fileupload
- 使用commons-fileupload实现文件上传
- 使用apache.commons.fileupload 进行文件上传
- 使用commons-fileupload实现文件上传
- 使用Commons-fileupload组件实现文件上传
- 使用Commons-fileupload组件实现文件上传
- Ubuntu下自动启动终端并运行脚本或命令
- 利用virt-manager安装虚拟机
- jsp 实现文件下载 java 实现文件下载 struts2 实现文件下载
- 9-patch图片
- android 适配器Adapter的使用总结
- Using a MultipartResolver with Commons FileUpload[就是使用commons FileUpload上传文件]
- OpenCV中GPU模块(CUDA)函数
- 仿网易主界面左右滑动以及顶部大图,下拉刷新.上拉加载更多等功能集成控件
- linux定时执行任务cron
- 加密狗工作原理
- Hibernate从入门到精通(九)一对多双向关联映射
- oracle 协议适配器错误,无法登陆
- uva11111 Generalized Matrioshkas (模拟 + 栈)
- Spring3核心技术之事务管理机制