struts 2文件上传
来源:互联网 发布:81端口批量入侵摄像头 编辑:程序博客网 时间:2024/04/30 07:39
第一步:在WEB-INF/lib下加入commons-fileupload-1.2.1.jar、commons-io-1.3.2.jar。这两个文件可以从http://commons.apache.org/下载。 第二步:把form表的enctype设置为:“multipart/form-data“,如下: <form enctype="multipart/form-data" action="${pageContext.request.contextPath}/xxx.action" method="post">//一定要加提交方法了 <input type="file" name="uploadImage"> </form> 第三步:在Action类中添加以下属性,属性红色部分对应于表单中文件字段的名称: public class HelloWorldAction{ private File uploadImage;//得到上传的文件 和表单里的name属性值相同 private String uploadImageContentType;//得到文件的类型 和表单里的name属性值相同 后面固定 private String uploadImageFileName;//得到文件的名称 和表单里的name属性值相同 后面固定 //这里略省了属性的getter/setter方法 public String upload() throws Exception{ String realpath = ServletActionContext.getServletContext().getRealPath("/images"); File file = new File(realpath); if(!file.exists()) file.mkdirs(); FileUtils.copyFile(uploadImage, new File(file, uploadImageFileName)); return "success"; } } //////////////////////////////////////////////////////多文件上传////////////////////////////////////////////////////////////////// 第一步:在WEB-INF/lib下加入commons-fileupload-1.2.1.jar、commons-io-1.3.2.jar。这两个文件可以从http://commons.apache.org/下载。 第二步:把form表的enctype设置为:“multipart/form-data“,如下: <form enctype="multipart/form-data" action="${pageContext.request.contextPath}/xxx.action" method="post"> <input type="file" name="uploadImages"> <input type="file" name="uploadImages"> </form> 第三步:在Action类中添加以下属性,属性红色部分对应于表单中文件字段的名称: public class HelloWorldAction{ private File[] uploadImages;//得到上传的文件 private String[] uploadImagesContentType;//得到文件的类型 private String[] uploadImagesFileName;//得到文件的名称 //这里略省了属性的getter/setter方法 public String upload() throws Exception{ String realpath = ServletActionContext.getServletContext().getRealPath("/images"); File file = new File(realpath); if(!file.exists()) file.mkdirs(); for(int i=0 ;i<uploadImages.length; i++){ File uploadImage = uploadImages[i]; FileUtils.copyFile(uploadImage, new File(file, uploadImagesFileName[i])); } return "success"; }}
- struts文件上传2
- struts 2文件上传
- Struts 2 文件上传
- struts 2实现文件上传
- struts 2 中的文件上传
- Struts 2 文件上传教程
- struts 2多文件上传
- Struts 2 实现上传文件
- struts 2 文件上传问题
- struts 2的文件上传
- Struts 2 之文件上传
- Struts 2 之文件上传
- 在Struts 2中实现文件上传
- 在Struts 2中实现文件上传
- 在Struts 2中实现文件上传
- 在Struts 2中实现文件上传
- 在Struts 2中实现文件上传
- 在Struts 2中实现文件上传
- Struts 2 校验器的使用例子
- 相册浏览
- 移动视频监控(2)---原型开发---(RTSP)Live555
- Mars Android视频学习笔记——01_23_WIFI网络操作
- Struts 2输入校验/采用手工编写/基于XML配置
- struts 2文件上传
- Struts 2获取HttpServletRequest / HttpSession / ServletContext / HttpServletResponse对象
- 获取玩家Flash的相关信息
- Struts 2自定义类型转换器
- 一位母亲参观CES之后的最大遗憾
- sPro__001Action名称的搜索顺序
- 配置文件struts.xml详解
- Struts2应用的配置文件
- RowsCopy 用法