- 浏览: 1371380 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (551)
- 计划 (4)
- java (115)
- oracle (60)
- ajax (3)
- javascript (64)
- 计算机操作技巧集 (11)
- 近期关注话题 (10)
- 随想 (13)
- html (6)
- struts (15)
- hibernate (16)
- spring (2)
- game (0)
- Eglish (10)
- DisplayTag (6)
- jsp (18)
- css (3)
- eclipse (3)
- 其他知识 (8)
- 备用1 (12)
- 备用2 (1)
- 笑话-放松心情 (9)
- 设计 (1)
- 设计模式 (1)
- 数据结构 (0)
- office办公软件 (5)
- webwork (0)
- tomcat (2)
- MySql (1)
- 我的链接资源 (5)
- xml (2)
- servlet (0)
- PHP (13)
- DOM (0)
- 网页画图vml,canvas (1)
- 协议 (2)
- 健康 (3)
- 书籍下载 (1)
- jbpm (1)
- EXT (1)
- 自考 (2)
- 报表 (4)
- 生活 (64)
- 操作系统基础知识 (2)
- 测试 (2)
- guice (1)
- google学习 (2)
- Erlang (1)
- LOG4J (2)
- wicket (1)
- 考研 (1)
- 法律 (1)
- 地震 (1)
- 易学-等等相关 (1)
- 音乐 (1)
- 建站 (4)
- 分享说 (3)
- 购物省钱 (0)
- linux (1)
最新评论
-
zenmshuo:
如果使用SpreadJS这一类的表格工具,应该能更好的实现这些 ...
js中excel的用法 -
hjhj2991708:
第一个已经使用不了
jar包查询网站 非常好用! -
jiangmeiwei:
...
中文乱码 我的总结 不断更新 -
gary_bu:
...
response.sendRedirect 中文乱码问题解决 -
hnez:
多谢指点,怎么调试也不通,原来我在<body>&l ...
ExtJs IE ownerDocument.createRange() 错误解决方案
StrutsFileUpload
File Upload - Simple Example
HTML
This isn't specific to Struts, but gives a simple example of the HTML required to upload a single file.
Two things are needed in the html page. Firstly, the form needs to specify an enctype of multipart/form-data and secondly an <input> form control of type file.
<form name="myForm" method="post" action="/mywebapp/uploadMyFile.do" enctype="multipart/form-data">
Select File: <input type="file" name="myFile"> </br>
<input type="submit" value="Upload File">
</form>
JSP
The above HTML can be generated using the Struts tags in the following way
<html:form action="/uploadMyFile.do" enctype="multipart/form-data">
Select File: <html:file property="myFile"/> <br/>
<html:submit value="Upload File"/>
</html:form>
ActionForm
The ActionForm needs a property of type FormFile.
Regular ActionForms
import org.apache.struts.upload.FormFile;
public class MyActionForm extends ActionForm {
private FormFile myFile;
public void setMyFile(FormFile myFile) {
this.myFile = myFile;
}
public FormFile getMyFile() {
return myFile;
}
}
Dyna ActionForms
In the struts-config.xml
<form-bean name="myForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="myFile" type="org.apache.struts.upload.FormFile"/>
</form-bean>
Whats Needed in the Action
Nothing special really, just retrieve the FormFile from the ActionForm, as you would any other property, and process it as you like. You can get the file name, size and file contents from the FormFile.
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
MyActionForm myForm = (MyActionForm)form;
// Process the FormFile
FormFile myFile = myForm.getMyFile();
String contentType = myFile.getContentType();
String fileName = myFile.getFileName();
int fileSize = myFile.getFileSize();
byte[] fileData = myFile.getFileData();
...
}
File Upload Configuration
The following parameters can be set in the <controller> element of the struts-config.xml to configure file upload:
bufferSize - The size (in bytes) of the input buffer used when processing file uploads. Default is 4096.
maxFileSize - The maximum size (in bytes) of a file to be accepted as a file upload. Can be expressed as a number followed by a "K", "M", or "G", which are interpreted to mean kilobytes, megabytes, or gigabytes, respectively. Default is 250M.
multipartClass - The fully qualified Java class name of the multipart request handler class to be used with this module. Defaults is org.apache.struts.upload.CommonsMultipartRequestHandler.
tempDir - Temporary working directory to use when processing file uploads.
Above taken from the Configuration section in the User Guide.
Plugging in an Alternative File Upload Mechanism
By default Struts uses Commons File Upload.
Alternative implementations can be plugged as long as they implement the org.apache.struts.upload.MultipartRequestHandler interface and Struts configured to use that implementation by specifying it in the multipartClass parameter in the <controller> element of the struts-config.xml
Fair Warning: The MultipartRequestHandler interface is almost certain to change in a Struts 1.3 or higher release.
last edited 2006-08-18 15:39:41 by OttoPalminkoski
File Upload - Simple Example
HTML
This isn't specific to Struts, but gives a simple example of the HTML required to upload a single file.
Two things are needed in the html page. Firstly, the form needs to specify an enctype of multipart/form-data and secondly an <input> form control of type file.
<form name="myForm" method="post" action="/mywebapp/uploadMyFile.do" enctype="multipart/form-data">
Select File: <input type="file" name="myFile"> </br>
<input type="submit" value="Upload File">
</form>
JSP
The above HTML can be generated using the Struts tags in the following way
<html:form action="/uploadMyFile.do" enctype="multipart/form-data">
Select File: <html:file property="myFile"/> <br/>
<html:submit value="Upload File"/>
</html:form>
ActionForm
The ActionForm needs a property of type FormFile.
Regular ActionForms
import org.apache.struts.upload.FormFile;
public class MyActionForm extends ActionForm {
private FormFile myFile;
public void setMyFile(FormFile myFile) {
this.myFile = myFile;
}
public FormFile getMyFile() {
return myFile;
}
}
Dyna ActionForms
In the struts-config.xml
<form-bean name="myForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="myFile" type="org.apache.struts.upload.FormFile"/>
</form-bean>
Whats Needed in the Action
Nothing special really, just retrieve the FormFile from the ActionForm, as you would any other property, and process it as you like. You can get the file name, size and file contents from the FormFile.
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
MyActionForm myForm = (MyActionForm)form;
// Process the FormFile
FormFile myFile = myForm.getMyFile();
String contentType = myFile.getContentType();
String fileName = myFile.getFileName();
int fileSize = myFile.getFileSize();
byte[] fileData = myFile.getFileData();
...
}
File Upload Configuration
The following parameters can be set in the <controller> element of the struts-config.xml to configure file upload:
bufferSize - The size (in bytes) of the input buffer used when processing file uploads. Default is 4096.
maxFileSize - The maximum size (in bytes) of a file to be accepted as a file upload. Can be expressed as a number followed by a "K", "M", or "G", which are interpreted to mean kilobytes, megabytes, or gigabytes, respectively. Default is 250M.
multipartClass - The fully qualified Java class name of the multipart request handler class to be used with this module. Defaults is org.apache.struts.upload.CommonsMultipartRequestHandler.
tempDir - Temporary working directory to use when processing file uploads.
Above taken from the Configuration section in the User Guide.
Plugging in an Alternative File Upload Mechanism
By default Struts uses Commons File Upload.
Alternative implementations can be plugged as long as they implement the org.apache.struts.upload.MultipartRequestHandler interface and Struts configured to use that implementation by specifying it in the multipartClass parameter in the <controller> element of the struts-config.xml
Fair Warning: The MultipartRequestHandler interface is almost certain to change in a Struts 1.3 or higher release.
last edited 2006-08-18 15:39:41 by OttoPalminkoski
发表评论
-
TilesRequestProcessor - Tiles definition factory found for request processor ''
2011-11-03 15:39 2508TilesRequestProcessor - T ... -
jar包查询网站 非常好用!
2009-12-28 11:47 13399java jar包查询 根据类查询所在的java包 http ... -
tomcat 启动错误 java.lang.UnsupportedClassVersionError: Bad version number in .class
2009-11-27 08:53 2260请访问http://ddgrow.com/bad-versio ... -
arrayToString
2009-04-07 09:01 1425原文:http://leepoint.net/notes-ja ... -
native2ascii
2009-04-02 12:00 1195D:\>native2ascii 中国 \u4e2d\u ... -
java swing 架构
2009-03-04 15:03 2326下面是偶尔找到的一篇 相当好的文章 ,针对 java swin ... -
红帽企业5序列号
2009-02-27 09:11 2549这是从[url]http://www.21codes.com/ ... -
中文乱码 我的总结 不断更新
2009-02-23 09:51 2310java中文乱码问题 1、jsp中文乱码 <0& ... -
websphere 数据库连接
2009-02-19 17:47 2132问个问题: 应用服务器: websphere 连接池:pr ... -
打开java控制台的方法
2009-02-10 17:10 3065D:\Program Files\Java\jre6\bin\ ... -
log4j weblogic 问题
2009-01-21 15:08 1948问题是这样的 最初在tomcat5.5下面开发,使用了log ... -
log4j weblogic 问题
2009-01-21 15:07 0问题是这样的 最初在tomcat5.5下面开发,使用了log ... -
java.lang.NoClassDefFoundError in quartz
2008-12-24 15:35 2927quartz-1.5.2.jar tomcat5.5 当使 ... -
java 得到运行时系统中的内存信息
2008-12-19 20:54 1531这个在tomcat下面使用过,在引记录下来,以后方便查找 Ru ... -
log4j
2008-12-13 11:32 905讲解了用xml配置,还有例子,以及对 levelmin lev ... -
servlet 2.3 规范
2008-12-02 20:55 0servlet 2.3 规范 http://www.orio ... -
session 问题
2008-11-26 16:41 1007问个问题,如下: 我要在一个A系统中,通过一个弹出窗口,超链接 ... -
java 反编译工具
2008-10-08 11:03 2001从哪找到的给忘了,用起来不错,放在这里,以后找起来方便 ,有需 ... -
thinking in java 读书笔记
2008-10-06 22:09 1345记录下来,以便以后查看 thinking in java 4t ... -
RSA 算法 java版本<转>
2008-09-23 18:28 2426原文地址:http://www.cs.princeton.ed ...
相关推荐
毕设和企业适用springboot企业数据管理平台类及跨境电商管理平台源码+论文+视频
功能说明: 环境说明: 开发软件:VS 2017 (版本2017以上即可,不能低于2017) 数据库:SqlServer2008r2(数据库版本无限制,都可以导入) 开发模式:mvc。。。
labview程序代码参考学习使用,希望对你有所帮助。
毕设和企业适用springboot社交应用平台类及用户数据分析平台源码+论文+视频
大米外贸商城系统 简称damishop 完全开源版,只需做一种语言一键开启全球133中语言自动翻译功能,价格实现自动汇率转换,集成微信支付宝 paypal以及国外主流支付方式,自带文章博客系统。 软件架构 基于MVC+语言包模式,增加控制台,API导入产品方便对接其他系统(带json示例数据)。 使用要求 PHP7.4+ MYSQL5.6+ REDIS(可选) 安装方法 composer install 打开安装向导安装 http://您的域名/install 特色 1、缓存层增加时间与批量like删除 2、API产品导入方便对接其他系统 3、增加控制台命令行,命令行生成语言翻译包 4、后台一键开启自动翻译模式,支持全球133中语言,由于google代理翻译需要收费,这个功能需要付费。 5、可选购物车与ajax修改购物车产品 6、一键结算checkout 7、增加网站前台自定义路由 方便seo 更新日志 v3.9.7 集成鱼码支付接口,方便个人站长即使收款到账使用 v3.9.3 更新内容 1:增加ueditor与旧编辑器切换 2:增加可视化布局插
labview程序代码参考学习使用,希望对你有所帮助。
毕设和企业适用springboot生鲜鲜花类及生物识别平台源码+论文+视频.zip
毕设和企业适用springboot企业健康管理平台类及视觉识别平台源码+论文+视频.zip
毕设和企业适用springboot视频编辑类及餐饮管理平台源码+论文+视频.zip
labview程序代码参考学习使用,希望对你有所帮助。
毕设和企业适用springboot社区物业类及智能仓储平台源码+论文+视频
毕设和企业适用springboot企业知识管理平台类及人工智能医疗平台源码+论文+视频
毕设和企业适用springboot汽车电商类及新闻传播平台源码+论文+视频
毕设和企业适用springboot生鲜鲜花类及全渠道电商平台源码+论文+视频.zip
毕设和企业适用springboot企业数据智能分析平台类及投票平台源码+论文+视频
毕设和企业适用springboot全渠道电商平台类及人工智能客服平台源码+论文+视频
毕设和企业适用springboot企业云存储平台类及AI数据标注平台源码+论文+视频
毕设和企业适用springboot人工智能客服系统类及旅游规划平台源码+论文+视频
毕设和企业适用springboot社交电商类及环境监控平台源码+论文+视频
毕设和企业适用springboot生鲜鲜花类及大数据存储平台源码+论文+视频