struts2文件上传
来源:互联网 发布:java仿qq好友列表 编辑:程序博客网 时间:2024/06/05 13:31
单文件上传:
1.先导入commons-fileupload-1.2.2.jar和commons-io-2.0.1.jar
2.前端jsp代码
<div> <label for="file">上传头像:</label> <input type="file" id="img" name="img"> </div>
3.后端action的接收
//注意,file并不是指前端jsp上传过来的文件本身,而是文件上传过来存放在临时文件夹下面的文件 private File img; //提交过来的file的名字 private String imgFileName; //提交过来的file的MIME类型 private String imgContentType;public String register() throws Exception{ if (img!=null) { String imageName=DateUtil.getCurrentDateStr(); String realPath=ServletActionContext.getServletContext().getRealPath("/image/bloger"); String imageFile=imageName+"."+imgFileName.split("\\.")[1]; String []names = img.getName().split("\\."); File saveFile=new File(realPath,imageFile); FileUtils.copyFile(img, saveFile); bloger.setImageName("image/bloger/"+imageFile); }}
4.在struts.xml中设置struts.multipart.saveDir属性和值。
http://jingyan.baidu.com/album/2a138328aed685074a134fca.html
0 0
- struts2上传文件(三) struts2上传文件
- [Struts2]Struts2的文件上传
- Struts2的文件上传
- Struts2文件上传
- Struts2 上传文件实例
- struts2文件上传
- struts2文件上传
- Struts2的文件上传
- struts2-上传文件(1)
- struts2-上传文件(2)
- Struts2上传文件示例
- struts2文件上传
- Struts2实现文件上传
- struts2文件上传
- Struts2 文件上传
- ext + struts2 上传文件
- Struts2 文件上传
- Struts2的文件上传
- Linux下编译安装PHP环境
- Java上传下载excel、解析Excel、生成Excel的问题
- 批量更改文件的扩展名
- Android四大组件之Service(服务)简单总结
- 伪造邮件艺术
- struts2文件上传
- MySQL5.6.11安装步骤(Windows7 64位)
- setValue 和 setObject 的区别
- NOIP2005提高组 过河
- Linux下随机10字符病毒的清除
- 杂记_比赛的一些记录
- 加速Android Studio---Gradle构建
- mongodb 批量操作
- CentOS 6.3下 源码包安装LAMP(Linux+Apache+Mysql+Php)环境