- 浏览: 139247 次
- 性别:
- 来自: 南京
文章分类
- 全部博客 (129)
- framework (18)
- Java (25)
- web2.0 (7)
- Oracle (23)
- 框架师 (20)
- design pattern (5)
- j2ee (6)
- 日常问题收集 (51)
- linux (12)
- Oralce优化 (4)
- life (3)
- sqlplus (1)
- sql (2)
- C# (4)
- mysql (9)
- 拿来主义 (12)
- 标签 (0)
- ThinkPHP (1)
- python (1)
- mybatis (2)
- html5 (1)
- jquery (2)
- hadoop (3)
- git (1)
- struts2 (1)
- shiro (1)
- struts (1)
最新评论
-
xiao88xian:
...
jQuery常用经典技巧
struts2文件上传下载非常的简单。
给我们提供了非常简洁的方式来上传文件。
其中我们需要用到的jar文件主要是:commons-io-1.3.2.jar 和 commons-fileupload-1.2.1.jar
然后需要注意的是,我们在写表单的时候,就是必须在写页面表单的时候 需要 将form表单的
enctype="multipart/form-data"
前台
<form enctype="multipart/form-data" action="${pageContext.request.contextPath}/test/file/upload.action" method="post"> <input type="file" name="uploadImage"> <input type="submit" value="upload"> </form>
struts2配置文件
<package name="file" namespace="/test/file" extends="struts-default"> <action name="*" class="com.anduo.action.FileUploadAction" method="{1}"> <result name="success">/success.jsp</result> </action> </package>
后台Action 代码
package com.anduo.action; import java.io.File; import org.apache.commons.io.FileUtils; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionContext; public class FileUploadAction { private File uploadImage;// 得到上传的文件 特别注意的是在这里的文件名必须跟前台的input 标签中的name 一致 private String uploadImageContentType;// 得到文件的类型 private String uploadImageFileName;// 得到文件的名称 // 这里略省了属性的getter/setter方法 public String upload() throws Exception { // 获得项目路径 String realpath = ServletActionContext.getServletContext().getRealPath( "/images"); if (uploadImage != null) { File file = new File(realpath); if (!file.exists()) { file.mkdirs(); } FileUtils.copyFile(uploadImage, new File(file, uploadImageFileName)); ActionContext.getContext().put("message", "文件上传成功!" + realpath + "/" + uploadImageFileName); } return "success"; } }
success.jsp
${message}
请看效果
上文文件成功了吧。
如果我们没有指定上传文件的存放路径,struts2会在action结束后移除临时文件
也就是我们根本就找不到我们上传的东西了。吼吼~~~
发表评论
-
MyBatis延迟加载
2013-05-26 20:15 806当你要使用one to one,many to one 就 ... -
mybatis 自身关联 映射
2013-05-22 14:48 3212使用mybatis的时候遇到关联问题。 可以参考如下 ... -
ThinkPHP学习笔记
2013-05-11 23:09 799from:http://www.thinkphp.cn/in ... -
解决subclipse报错:svn: Can't open file 'D:\project\Xxx.java.svn-base': 系统找不到指定的文件
2013-03-23 16:49 1922环境为:XP, eclipse, subclipse。 我想 ... -
hibernate4+spring3.1整合常见问题解决方法
2013-03-21 19:21 774由于目前网上很少有关于hibernate4+spring3. ... -
解决maven仓库中找不到ojdbc驱动的问题
2013-02-21 16:51 857maven仓库中的ojdbc下载需要oracle的官方授权, ... -
Ant-Ivy使用
2013-02-21 12:27 1028转至:http://blog.csdn.net/leon70 ... -
ibatis(2)关于配置文件的书写
2012-04-06 13:29 1314最近做了些ibatis 的练习,以及spring对ibatis ... -
spring-ibatis-ext-plugin.1.0.0 扩展ibaits原生SQL(转载)
2012-04-01 16:25 993转载至http://download.csdn.net/ ... -
ibatis初学001
2012-03-31 14:25 1054目录:一、iBatis简介二、iBatis基础操作演示三、如何 ... -
spring2.5+hibernate2.3整合 annotation
2011-12-31 21:48 896晚上花了点时间写了个spring+hibernate的整合 ... -
Hibernate学习总结001-hibernate概述
2011-10-06 21:35 803说到hiberna ... -
Spring-AOP底层原理-JDK动态代理---转载
2011-10-07 19:29 1610原文http://blog.zdnet.com.cn/html ... -
struts2_ognl表达式
2011-12-27 09:07 699OGNL是Object Graphic Navigati ... -
Action中result的各种转发类型——struts2_003
2012-03-31 14:25 1151<action name="hellow ... -
Action配置中的各项默认值——struts2_002
2011-12-23 12:36 1003<package name="it ... -
Action名称的搜索顺序——struts2_001
2011-12-23 12:33 7341.获得请求路径的URI,例如url是:http://se ...
相关推荐
Struts1的fileupload的文件上传
struts_fileupload文件上传Struts2
struts2 文件上传 struts2上传标签file fileuploadstruts2 文件上传 struts2上传标签file fileuploadstruts2 文件上传 struts2上传标签file fileupload
struts2 fileupload 文件上传
java 文件上传(包括struts2文件上传,smartupload,基于apatch 的fileupload的文件上传):该文件包括文件上传的多个实例:有基于strtus2自带的文件上传实例、smartupload文件实例 和基于aptche自带的fileupload 的...
Struts 2是通过Commons FileUpload文件上传。Commons FileUpload通过将HTTP的数据保存到临时文件夹,然后Struts使用fileUpload拦截器将文件绑定到Action的实例中。从而我们就能够以本地文件方式的操作浏览器上传的...
Struts 2是通过Commons FileUpload文件上传。Commons FileUpload通过将HTTP的数据保存到临时文件夹,然后Struts使用fileUpload拦截器将文件绑定到Action的实例中。从而我们就能够以本地文件方式的操作浏览器上传的...
最近在做struts2的学习研究,这里共享一份完整能运行的示例
这是struts2中文件上传的必须组件,
java实现的文件上传下载FileUpLoad,内含SQL文件,使用Oracle数据库,struts2组件包装,包装流加快下载,可上传可下载,适合初学者学习使用!
struts2上传文件需要的jar包 commons-fileupload-1.2.1.jar和commons-io-1.3.2.jar
这是我结合网络资源。。和我对一些平时知识积累做的一个文件上传。。可能还存在漏洞。。请爱学者补全。。它将是一个完美的文件上传资料。。希望能给你的学习带来方便
struts2+jquery+ajax实现了文件的异步上传,的MyEclipse编写的简单项目
最近进行了整理,总结了一下,供大家参考。
struts2中的文件上传和下载: 1.首先导入commons-fileupload-1.2.1.jar和commons-io-1.4.jar两个jar包 2.其次JSP页面中的文件上传控件所在的form必须设置属性enctype="multipart/form-data" 3.再次,struts2中...
struts1.2 简单文件上传例子(用eclipse3.4打开运行即可)
struts2相关经典教程 fileupload struts2
Common-FileUpload带进度条文件上传