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. RestTemplate请求https忽略证书认证

    RestTemplate是Spring提供的用于访问Rest服务的客户端,提供了多种便捷访问远程Http服务的方法,能够大大提高客户端的编写效率.RestTemplate 默认使用J2SE提供的方式( ...

  2. cglib动态代理(需导入cglib-nodep-2.1_3.jar)

    public interface AnimalInterface { public void cry(); } public class AnimalImpl implements AnimalInt ...

  3. pfSense 2.4.3 发布,包含重要的安全修复补丁

    pfSense 2.4.3 已发布,本次更新包含重要的安全修复和 bug 修复,还引入了一些新特性,具体如下. 值得关注的更新 包含一些重要的安全修复补丁: Kernel PTI mitigation ...

  4. Python+Opencv进行识别相似图片

    http://blog.csdn.net/feimengjuan/article/details/51279629

  5. 为Pdf批量添加水印

    Itext官网下载jar包 /** * PDF工具类 */ public class PdfUtil { public static void main(String[] args) throws E ...

  6. poj-3046-dp

    Ant Counting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6829   Accepted: 2514 Desc ...

  7. 在Hibernate中使用原生SQL语句

    使用原生SQL查询必须注意:程序必须选出所有的数据列才可被转换成持久化实体.假设实体在映射时有一个<many-to-one../>的关联指向另外一个实体,则SQL查询中必须返回该<m ...

  8. Centos7 使用Dockerfile 制作自己的Dotnetcore程序镜像

    准备Centos7环境及Docker环境 从Docker hub拉取 Microsoft/dotnet 基础镜像(可以使用国内加速) 向Centos7指定目录上传Dotnet Core程序,目录: / ...

  9. 032——VUE中表单控件处理之复选框的处理

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. js自定义对象.属性 笔记

    <一> js自定义对象 一,概述 在Java语言中,我们可以定义自己的类,并根据这些类创建对象来使用,在Javascript中,我们也可以定义自己的类,例如定义User类.Hashtabl ...