java.lang.NumberFormatException: For input string: "null"

在开发中你是否遇到过这样的问题,不管请求到的值是什么都能进入不为null或”“的判断中,如下例:

Stringtemp=req.getParameter("status");//任务状态

int status= 0;//任务状态

   if(temp!=null&&!"".equals(temp))

   {

      status=Integer.parseInt(temp);

   }

   json.put("status",status);

运行时temp总能进入if条件判断,并且你会得到错误提示如下:

java.lang.NumberFormatException: For inputstring: "null"

       atjava.lang.NumberFormatException.forInputString(NumberFormatException.

java:48)

       at java.lang.Integer.parseInt(Integer.java:447)

       at java.lang.Integer.parseInt(Integer.java:497)

       atcom.runqianapp.workflow.servlet.WorkShowServlet.getJson(WorkShowServl

et.java:102)

       atcom.runqianapp.workflow.servlet.WorkShowServlet.doPost(WorkShowServle

t.java:49)

       atjavax.servlet.http.HttpServlet.service(HttpServlet.java:709)

       atjavax.servlet.http.HttpServlet.service(HttpServlet.java:802)

       atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl

icationFilterChain.java:237)

       atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF

ilterChain.java:157)

这是为什么呢?我再着困扰了好长时间才找到原因,其实是错误的理解了提示 Forinput string: "null"

这句话的意思不是输入的是空值,而是说你输入的事String类型的字符串”null“

明白为什么错了就好解决了,解决方法如下:

Stringtemp=req.getParameter("status");//任务状态

int status= 0;//任务状态

   if(temp!=null&& !"".equals(temp) &&!"null".equals(temp))

   {

    status=Integer.parseInt(temp);

   }

   json.put("status",status);

只需要加上一条不为字符串”null“的判断即可

For input string: "null"的更多相关文章

  1. NumberFormatException: For input string: "null"

    日志: [INFO-2016/08/04/16/:21/:25]ProjectCommonFormController.(78) - 审批[同意]入参-[string]commonFormDtoStr ...

  2. myBatis-plus异常提示For input string: "{0=null}"

    异常信息 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.Per ...

  3. java.lang.NumberFormatException: For input string: "Y"

    nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.  ...

  4. mybatis 报错:Caused by: java.lang.NumberFormatException: For input string

    mybatis的if标签之前总是使用是否为空,今天要用到字符串比较的时候遇到了困难,倒腾半天,才在一个论坛上找到解决方法.笔记一下,如下: 转自:https://code.google.com/p/m ...

  5. MyBatis报错:Caused by: java.lang.NumberFormatException: For input string: "XX"

    <select id="sltTreatment" resultType="com.vitaminmd.sunny.core.bo.Treatment"& ...

  6. For input string: "..."

    之前在项目中通过EL表达式从cart 中取出itemPirce这个值时始终报:For input string: "${cart.itemPrice / 100}" 错误. 事故原 ...

  7. org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.NumberFormatException: For input string: "W%" ### Cause: java.lang.NumberFormatException: For input s

    一个常见的myBatis xml文件中的引号错误: org.apache.ibatis.exceptions.PersistenceException: ### Error querying data ...

  8. java.lang.NumberFormatException: For input string: "1608020001 " 错误

    错误: java.lang.NumberFormatException: For input string: "1608020001 "    at java.lang.Numbe ...

  9. java.lang.NumberFormatException: For input string:"filesId"

    做项目时候,页面获取出现了这个问题.找了好久一直以为是我字段或者是数据库字段问题导致引起的. 最后才发现是 struts2中jsp我写错了一个参数,一直导致报错.后来改了就好了. 当大家遇到这个问题的 ...

随机推荐

  1. Codeforces Round #360 (Div. 2) D. Remainders Game

    D. Remainders Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. 使用location.hash保存页面状态

    hash 属性是一个可读可写的字符串,该字符串是 URL 的锚部分(从 # 号开始的部分). 语法 location.hash 在我们的项目中,有大量ajax查询表单+结果列表的页面,由于查询结果是a ...

  3. ctci1.4

    ;     ;     ; i < len ; i++)         ;      +];     ; i < len; i++){         ';         }      ...

  4. ContentPresenter元素

    一个内容控件 分解它的“结构树”,肯定能够看到ContentPresenter“元素”,该元素的功能:用来为“内容控件”显示“Content”

  5. linux下查看进程路径

    在linux下查看进程大家都会想到用 ps -ef|grep XXX可是看到的不是全路径,怎么看全路径呢?每个进程启动之后在 /proc下面有一个于pid对应的路径例如:ps -ef|grep pyt ...

  6. Codeforces Round #423

    这一次又崩了,最后只a了一题(还是被hack后才发现的错误) 第一题水题,多用一个数保存2-1后的数,注意先用2的桌子,再用这个 #include<map> #include<set ...

  7. NVML查询显卡信息

    前段时间做英伟达硬解得时候,显卡总是莫名挂掉,后来发现是因为显卡温度过高掉了.这几天找到CUDA中有NVML工具可以查看显卡信息,nvidia-smi也是基于这个工具包. 使用的CUDA版本为CUDA ...

  8. Netty实例几则

    Netty是基于JDK NIO的网络框架 简化了NIO编程, 不用程序自己维护selector, 将网络通信和数据处理的部分做了分离 多用于做底层的数据通信, 心跳检测(keepalived) 1. ...

  9. 十九、dbms_resource_manager(用于维护资源计划,资源使用组和资源计划指令)

    1.概述 作用:用于维护资源计划,资源使用组和资源计划指令;包dbms_resource_manager_privs用于维护与资源管理相关的权限. 2.包的组成 1).dbms_resource_ma ...

  10. sql杂记

    Create procedure 存储过程的声明 PIVOT的一般语法是:PIVOT(聚合函数(列) FOR 列 in (…) )AS P 通俗简单的说:PIVOT就是行转列,UNPIVOT就是列传行 ...