struts2 文件上传
来源:互联网 发布:通达信原油看盘软件 编辑:程序博客网 时间:2024/06/06 05:58
如下是配置文件上传的大小;
<struts><!-- 全局配置 0.请求数据编码 --><constant name="struts.il8n.encoding" value="utf-8"></constant><!--1.修改struts默认的访问后缀 --><constant name="struts.action.extension" value="action,do,"></constant> <!--2.修改xml自动重新加载 --><constant name="struts.configuration.xml.reload" value="true"></constant><!--3.开启动态方法调用(默认不开启) --><constant name="struts.enable.DynamicMethodInvocation" value="true"></constant><!--4.**修改上传文件的最大大小为30M** --><constant name="struts.multipart.maxSize" value="30*1024*1024"></constant>
限制运行上传的文件的类型
<action name="demo1" class="cn.aufe.action.FileuploadDemo1"> <!--限制运行上传的文件的类型 --> <interceptor-ref name="defalutStack"> <!--限制运行文件的扩展名 --> <param name="fileUpload.allowedExtensions">txt,jpg</param> </interceptor-ref>
下面是示例:
public class FileuploadDemo1 extends ActionSupport { private File file1; private String file1FileName;//命名规则不可变 private String file1ContenType; public void setFile1(File file1) { this.file1 = file1; } public void setFile1FileName(String file1FileName) { this.file1FileName = file1FileName; } public void setFile1ContenType(String file1ContenType) { this.file1ContenType = file1ContenType; } @Overridepublic String execute() throws Exception { //huode 路径 String path = ServletActionContext.getServletContext().getRealPath("/upload"); //生成目标文件对象 File file = new File(path, file1FileName); //生成目标文件 FileUtils.copyFile(file1, file); return "hello";}
限制文件上传的类型:
<action name="demo1" class="cn.aufe.action.FileuploadDemo1"> <!-- 限制运行上传的文件的类型 --> <interceptor-ref name="defaultStack"> <!-- 限制运行文件的扩展名 --> <param name="fileUpload.allowedExtensions">txt,jpg,jar</param> <!--限制运行的类型(与上面同时使用取交集) --> <param name="fileUpload.allowedTypes">text/plain</param> </interceptor-ref>
阅读全文
1 0
- struts2上传文件(三) struts2上传文件
- [Struts2]Struts2的文件上传
- Struts2的文件上传
- Struts2文件上传
- Struts2 上传文件实例
- struts2文件上传
- struts2文件上传
- Struts2的文件上传
- struts2-上传文件(1)
- struts2-上传文件(2)
- Struts2上传文件示例
- struts2文件上传
- Struts2实现文件上传
- struts2文件上传
- Struts2 文件上传
- ext + struts2 上传文件
- Struts2 文件上传
- Struts2的文件上传
- 工厂方法模式(Factory Method Pattern)
- 监视并控制进程的创建
- Maven学习笔记二
- MySQL(二)
- LDA 视频收藏描述 预测分类
- struts2 文件上传
- git stash的使用
- 1087. All Roads Lead to Rome (30)
- dubbo源码深度解读四之remoting模块
- 中缀转后缀——逆波兰表示
- 【C语言】条件编译
- SELECT中OPTION元素的显示隐藏
- 【Java并发编程】Executor Interfaces
- Android 集成 FFmpeg (一) 基础知识及简单调用