Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > Java > 解决WEBWORK2.17中空文件上传时action报异常错误的问题
【标  题】:解决WEBWORK2.17中空文件上传时action报异常错误的问题
【关键字】:WEBWORK2.17,action
【来  源】:http://www.blogjava.net/jfy3d/archive/2006/02/20/31595.html

解决WEBWORK2.17中空文件上传时action报异常错误的问题

Your Ad Here

webwork里上传文件比较方便,几行代码就可以完成,
只是有个小问题,就是当form里的file控件没有选文件的时提交action 就会出现异常,
通常很多应用中不一定非要带文件上传的,这个应该算webwork一个bug吧。

从报错的地方可以查出是在fileupload拦截器中
String[] fileName = multiWrapper.getFileNames(inputName);
这一行开始中断掉的
就是multiWrapper.getFileNames(inputName);中出现空指针错误

如果webwork.properties中配置的是pell上传包

需要找到PellMultiPartRequest这个类的以下方法

public String[] getFileNames(String fieldName) {
                    // TODO - not sure about this - is this the filename of the actual file or
        // TODO - the uploaded filename as provided by the browser?
        // TODO - Not sure what version of Pell this class uses as it doesn't seem to be the latest  这里倒是说明了条件

            return new String[]{multi.getFile(fieldName).getName()};
}

可以看到
multi.getFile(fieldName).getName()如果文件为空肯定会报错的
可以先修改成以下方式
public String[] getFileNames(String fieldName) {


        if(multi.getFile(fieldName)!=null)
            return new String[]{multi.getFile(fieldName).getName()};
        else
            return new String[]{};
    }

这样form里file不选文件就不在出异常了

 

自己实现的一个加密算法:【上一篇】
D3D坐标系统和几何-DirectX Griaphic学习:【下一篇】
【相关文章】
  • Webwork 2.2的Action是否使用Spring的prototype?获取的性能对比
  • Webwork 2.2的Action是否使用Spring的prototype?获取的性能对比
  • Webwork 2.2的Action是否使用Spring的prototype?获取的性能对比
  • Webwork 2.2的Action是否使用Spring的prototype?获取的性能对比
  • Webwork 2.2的Action是否使用Spring的prototype?获取的性能对比
  • Webwork 2.2的Action是否使用Spring的prototype?获取的性能对比
  • Webwork 2.2的Action是否使用Spring的prototype?获取的性能对比
  • Webwork 2.2的Action是否使用Spring的prototype?获取的性能对比
  • Webwork 2.2的Action是否使用Spring的prototype?获取的性能对比
  • Webwork 2.2的Action是否使用Spring的prototype?获取的性能对比
  • 【随机文章】
  • OpenBSD全能服务器安装手册之系统安装篇--分区概念的相关介绍
  • AIX---12网络管理基础
  • 三十一岁祭
  • [Perl]访问文件时加锁-计数器
  • 用户手册(转载自国家计算机标准和文件模板)
  • 在Web应用程序中使用DBI
  • Karrigell 初次学习
  • JSTL详解(六)
  • 简易的四则运算
  • 西南石油大学无线校园网络规划
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.