开发者社区 问答 正文

参数在传递到action过程中遇到的问题?报错

在action接收参数写成Short.parseShort(getRequest().getParameter("sourceType"))时,debug测试参数错误为An exception occurred: java.lang.NumberFormatException,Console报错[com.scsoft.action.store.InstoreBillAction] ERROR om.scsoft.action.store.InstoreBillAction -null

当我参数写成Short.parseShort(getRequest().getParameter("sourceType").trim())时,debug测试参数错误为java.lang.NullPointerException at trim(),Console报错[com.scsoft.action.store.InstoreBillAction] ERROR om.scsoft.action.store.InstoreBillAction 

这个参数要怎么传递才能避免这个问题




展开
收起
爱吃鱼的程序员 2020-06-12 11:08:18 537 分享 版权
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    getParameter("sourceType"),是否真的获取到值了,没有值或者数据格式不对都是不行的。

    NumberFormatException是 Short.parseShort报错

    NullPointerException应该是 trim()

    后来我发现了,因为前台数据没有传递过来,所以后面无论怎么处理都是出错的

    引用来自“终日乾乾”的评论

    getParameter("sourceType"),是否真的获取到值了,没有值或者数据格式不对都是不行的。

    NumberFormatException是 Short.parseShort报错

    NullPointerException应该是 trim()

    2020-06-12 11:08:34
    赞同 展开评论
问答地址: