博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
apache common之文件上传
阅读量:4112 次
发布时间:2019-05-25

本文共 1132 字,大约阅读时间需要 3 分钟。

依赖jar:

commons-fileupload
commons-fileupload
1.3.1

采用fileupload组件进行上传,jsp页面:

领客网linkrmb.com数据上传单
用户账户(email):
上传文件:

对应的控制层的代码:

protected String storeFile(HttpServletRequest request, String baseDir)			throws Exception {		DiskFileItemFactory factory = new DiskFileItemFactory();		ServletFileUpload upload = new ServletFileUpload(factory);		List
items = upload.parseRequest(request); Iterator
itr = items.iterator(); String file = "common_data_file_"; while (itr.hasNext()) { FileItem item = (FileItem) itr.next(); if (!item.isFormField()) { System.out.println("上传文件的大小:" + item.getSize()); System.out.println("上传文件的类型:" + item.getContentType()); System.out.println("上传文件的名称:" + item.getName()); file = file + item.getFieldName(); item.write(new File(baseDir + File.separator + file)); break; } } return file; }

转载地址:http://blqsi.baihongyu.com/

你可能感兴趣的文章
ThreadLocal
查看>>
从Executor接口设计看设计模式之最少知识法则
查看>>
OKhttp之Call接口
查看>>
application/x-www-form-urlencoded、multipart/form-data、text/plain
查看>>
关于Content-Length
查看>>
WebRequest post读取源码
查看>>
使用TcpClient可避免HttpWebRequest的常见错误
查看>>
EntityFramework 学习之一 —— 模型概述与环境搭建 .
查看>>
C# 发HTTP请求
查看>>
初试visual studio2012的新型数据库LocalDB
查看>>
启动 LocalDB 和连接到 LocalDB
查看>>
Palindrome Number --回文整数
查看>>
Reverse Integer--反转整数
查看>>
Container With Most Water --装最多水的容器(重)
查看>>
Longest Common Prefix -最长公共前缀
查看>>
Letter Combinations of a Phone Number
查看>>
Single Number II --出现一次的数(重)
查看>>
Valid Parentheses --括号匹配
查看>>
Generate Parentheses--生成匹配括号(重)
查看>>
Remove Element--原地移除重复元素
查看>>