- 浏览: 1366237 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (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 2493TilesRequestProcessor - T ... -
jar包查询网站 非常好用!
2009-12-28 11:47 13392java jar包查询 根据类查询所在的java包 http ... -
tomcat 启动错误 java.lang.UnsupportedClassVersionError: Bad version number in .class
2009-11-27 08:53 2255请访问http://ddgrow.com/bad-versio ... -
arrayToString
2009-04-07 09:01 1416原文:http://leepoint.net/notes-ja ... -
native2ascii
2009-04-02 12:00 1176D:\>native2ascii 中国 \u4e2d\u ... -
java swing 架构
2009-03-04 15:03 2318下面是偶尔找到的一篇 相当好的文章 ,针对 java swin ... -
红帽企业5序列号
2009-02-27 09:11 2528这是从[url]http://www.21codes.com/ ... -
中文乱码 我的总结 不断更新
2009-02-23 09:51 2299java中文乱码问题 1、jsp中文乱码 <0& ... -
websphere 数据库连接
2009-02-19 17:47 2116问个问题: 应用服务器: websphere 连接池:pr ... -
打开java控制台的方法
2009-02-10 17:10 3041D:\Program Files\Java\jre6\bin\ ... -
log4j weblogic 问题
2009-01-21 15:08 1942问题是这样的 最初在tomcat5.5下面开发,使用了log ... -
log4j weblogic 问题
2009-01-21 15:07 0问题是这样的 最初在tomcat5.5下面开发,使用了log ... -
java.lang.NoClassDefFoundError in quartz
2008-12-24 15:35 2914quartz-1.5.2.jar tomcat5.5 当使 ... -
java 得到运行时系统中的内存信息
2008-12-19 20:54 1518这个在tomcat下面使用过,在引记录下来,以后方便查找 Ru ... -
log4j
2008-12-13 11:32 902讲解了用xml配置,还有例子,以及对 levelmin lev ... -
servlet 2.3 规范
2008-12-02 20:55 0servlet 2.3 规范 http://www.orio ... -
session 问题
2008-11-26 16:41 991问个问题,如下: 我要在一个A系统中,通过一个弹出窗口,超链接 ... -
java 反编译工具
2008-10-08 11:03 1993从哪找到的给忘了,用起来不错,放在这里,以后找起来方便 ,有需 ... -
thinking in java 读书笔记
2008-10-06 22:09 1340记录下来,以便以后查看 thinking in java 4t ... -
RSA 算法 java版本<转>
2008-09-23 18:28 2421原文地址:http://www.cs.princeton.ed ...
相关推荐
在这个"strutsFileUpLoad.zip"压缩包中,我们关注的是Struts2实现文件上传的功能。 在Java Web开发中,文件上传是一项常见需求,比如用户上传头像、提交文档等。Struts2提供了内置的支持来处理文件上传。这个压缩包...
- 在Struts2中,文件上传通常涉及到自定义Action类,例如`StrutsFileUpload`。这个类继承自`ActionSupport`,并实现了`ServletContextAware`接口。`ActionSupport`提供了异常处理和结果返回的基本结构,而`...
3. **Multipart解析器**:在现代Web应用中,经常使用Spring MVC或Struts2等框架,它们通常有自己的Multipart解析器,如Spring的`CommonsMultipartResolver`或Struts2的`StrutsFileUpload`。 4. **安全性考虑**:在...
在StrutsFileUpload项目中,我们将会使用Struts2的上传组件来完成这一任务。 1. **配置Struts2框架**: 在struts.xml配置文件中,我们需要添加支持文件上传的拦截器`paramsPrepareUploadInterceptor`,并设置相应...
我的第一个C#小程序之简单音乐播放器1731655933.html
练习springboot1 项目 模拟高并发秒杀,实现基本的登录、查看商品列表、秒杀、下单等功能,简单实现了系统缓存、降级和限流。SpringBoot + MyBatis + MySQL+Druid + Redis + RabbitMQ + Bootstrap + jQue….zip
html常规学习.zip资源资料用户手册
【项目资源】:包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。【项目质量】:所有源码都经过严格测试,可以直接运行。功能在确认正常工作后才上传。【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。【附加价值】:项目具有较高的学习借鉴价值,也可直接拿来修改复刻。对于有一定基础或热衷于研究的人来说,可以在这些基础代码上进行修改和扩展,实现其他功能。【沟通交流】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。鼓励下载和使用,并欢迎大家互相学习,共同进步。
HTML转PDF py脚本
yolo系列算法目标检测数据集,包含标签,可以直接训练模型和验证测试,数据集已经划分好,包含数据集配置文件data.yaml,适用yolov5,yolov8,yolov9,yolov7,yolov10,yolo11算法; 包含两种标签格:yolo格式(txt文件)和voc格式(xml文件),分别保存在两个文件夹中; yolo格式:<class> <x_center> <y_center> <width> <height>, 其中: <class> 是目标的类别索引(从0开始)。 <x_center> 和 <y_center> 是目标框中心点的x和y坐标,这些坐标是相对于图像宽度和高度的比例值,范围在0到1之间。 <width> 和 <height> 是目标框的宽度和高度,也是相对于图像宽度和高度的比例值
西电通院模电大作业课后题电路设计图24年
本文档主要讲述的是sqlserver内存释放;希望本文档会给有需要的朋友带来帮助;感兴趣的朋友可以过来看看
zw
发动机制造厂技术处安全、消防安全手册.docx
生产现场工艺文件执行检查管理流程说明.docx
Spring Boot集成Spring Security,HTTP请求授权配置:包含匿名访问、允许访问、禁止访问配置
通过设置截止频率和带宽来获取对应的滤波器参数
全国月尺度平均风速数据集(1961-2022, 0.25° × 0.25°)是一个高分辨率的网格化平均风速数据集,覆盖了中国大陆及周边地区。 该数据集通过科学方法整合气象观测和再分析数据,为气候研究、生态模型、农业生产、以及水资源管理等领域提供了重要支持。 数据下载后可显示详细信息。
styles
用VHDL语言设计电梯控制器.doc