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. spring mvc:内部资源视图解析器(注解实现)@Controller/@RequestMapping

    spring mvc:内部资源视图解析器(注解实现)@Controller/@RequestMapping 项目访问地址: http://localhost:8080/guga2/hello/prin ...

  2. Oracle归档的开启和关闭

    --1.开启归档 [步骤] a.一致性关闭数据库(shutdown [immediate | transactional |normal]) b.启动到mount阶段(startup mount) c ...

  3. flask学习(十二):for循环遍历

    一. 字典的遍历 语法和python一样,可以使用items().keys().values().iteritems().iterkeys().itervalues() {% for k, v in ...

  4. 搞懂分布式技术6:Zookeeper典型应用场景及实践

    搞懂分布式技术6:Zookeeper典型应用场景及实践 一.ZooKeeper典型应用场景实践 ZooKeeper是一个高可用的分布式数据管理与系统协调框架.基于对Paxos算法的实现,使该框架保证了 ...

  5. [nodejs]国内npm安装nodejs modules失败的几个解决方案

    使用npm安装node模块时经常有卡住安装失败的情况,如图所示.原因在于npm服务器在美国,还有就是某强大的防火墙作用.这样的问题导致很多新手放弃使用node,几乎每天都有新手再问这个问题.现在分享一 ...

  6. 几款必备LINUX的命令行神器

    Dstat & sar iostat, vmstat, ifstat 三合一的工具,用来查看系统性能(我在<性能调优攻略>中提到过那三个xxstat工具). 官方网站:http:/ ...

  7. 【Html 学习笔记】第四节——框架

    我们经常使用的网页可能不是一个单独的网页,而是多个嵌套的,那么就需要用到下面的技术. 垂直框架:<frameset cols=""> 这里需要注意的是:四个网页需要同时 ...

  8. The Enginer sample Test for GD temperature control (FCT, ATE, NPI,SMT, )

    For me it is a day of grief.................... 1 Communication with customer test methods. notes: T ...

  9. ajaxFileUpload的data数据带pre标签

    解决办法: var ret = jQuery.parseJSON(jQuery(data).text());

  10. Cannot forward after response has been committed 错误

    出现该错误的原因是:页面的跳转控制不好,换句话就是说程序的逻辑控制不好,导致了程序顺序执行的时候多次跳转到同一页面,有的程序员建议用多次使用return语句来返回,但是个人认为最好的还是自己要先理清页 ...