日期:2014-05-17  浏览次数:20753 次

jsp文本框取值问题
我在一个表单页面的一个文本输入框中做了数字限定。提交到一个servlet做处理。要取出这个文本框中的数字写入数据库,写入时总是报错。java.lang.NumberFormatException: null
这是为什么?
Java code

                  String s= request.getParameter("accounts"); 
        Integer i=new Integer(s); 
        int a=i.intValue();
        con.setPayAmount(a);

        //con.setRetentionMoney(Integer.parseInt(request.getParameter("Zbaccounts")));

                  //ba_info.setIncomingPwhether(java.lang.Integer.parseInt((String)request.getParameter("flag")));



用了以上三种取值方式运行到此处时均会报错。是错在哪里呢?

------解决方案--------------------
..晕。。。String类型的可以这样转换成int的吗?
应该这样:
int a = Integer.parseInt(s);
------解决方案--------------------

应该是request.getParameter("accounts"); 获取的值为null,所有转换成报null
------解决方案--------------------
错误是
java.lang.NumberFormatException: null
空值无法转换成整型,应该是你jsp端传递数据出问题的,数据没有传递过来,表单提交的代码贴出来看看吧
------解决方案--------------------
检查一下输入框的name是不是accounts
------解决方案--------------------
String s= request.getParameter("accounts"); 
这里肯定是没有值的,不然就是类型转换的错误
而不是NumberFormatException(数字格式化异常:空)
首先确保s有值,你在进行下一步操作