webx3文件上传

一、定义form

<form method="post" name="import_form" id="import_form" enctype="multipart/form-data">
        <table class="table table-condensed">
            $csrfToken.hiddenField
            <tr>
                <td>
                    文件
                </td>
                <td>
                    <input type="file" class="form-control" id="import_file" name="import_file"/>
                </td>
            </tr>

            <tr>
                <td><input type="hidden" name="action" value="importFaultAction"/></td>
                <td><input type="submit" id="import_confirm" name="import_confirm" value="上传"/></td>
            </tr>
        </table>
    </form>


二、配置webx.xml文件

Upload服务的配置参数

<services:upload sizeMax="300M"
                     fileSizeMax="200M"
                     repository="/tmp"
                     sizeThreshold="1M"/>


参数名称说明
sizeMaxHTTP请求的最大尺寸(字节,支持K/M/G),超过此尺寸的请求将被抛弃。值-1表示没有限制。
fileSizeMax单个文件允许的最大尺寸(字节,支持K/M/G),超过此尺寸的文件将被抛弃。值-1表示没有限制。
repository暂存上传文件的目录。 注意,这个目录是用Spring ResourceLoader装载的,而不是一个物理路径。关于|ResourceLoader,详见ResourceLoading服务的文档。
sizeThreshold将文件放在内存中的阈值(字节,支持K/M/G),小于此值的文件被保存在内存中。
keepFormFieldInMemory是否将普通的form field保持在内存里? 默认为false,但当sizeThreshold为0时,默认为true。

配置过滤参数

<services:request-contexts>
        <request-contexts:parser URIEncoding="UTF-8" useBodyEncodingForURI="false" >
            <request-contexts:filters xmlns="http://www.alibaba.com/schema/services/request-contexts/parser/filters">
                <!-- 文件上传白名单 -->
                <uploaded-file-whitelist extensions="xls" />
            </request-contexts:filters>
        </request-contexts:parser>
</services:request-contexts>


上面的配置将会禁止文件名后缀不在列表中的文件被上传到服务器上。如果做得更好一点,你甚至可以对上传文件进行病毒扫描。

编写Java文件

public class ImportFaultAction {
    public void execute(
            TurbineRunData rundata, Context context) throws IOException, ServletException {
        FileItem file = rundata.getParameters().getFileItem("import_file"); //该文件为上传的文件
        //InputStream in = file.getInputStream();
    }
}


PS:具体请参考 http://www.openwebx.org/docs/Webx3_Guide_Book.html#d0e7262

Webx框架指南: http://www.openwebx.org/docs/Webx3_Guide_Book.html

转自:http://www.hollischuang.com/archives/507

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值