request.getParameter()得到的数值为'6',使用了Integer.parseInt()方法不能转换成int,请教还有何方法能转化成int

解决方案 »

  1.   

    使用了Integer.parseInt()方法不能转换成int????
      

  2.   

    int i = new Integer(i).parseInt(request.getParameter("String"));
      

  3.   

    int i=Integer.parseInt(request.getParameter())
      

  4.   

    这应该很简单啊,Integer.parseInt()的参数必须是String类型的,而这里是char类型,当然不行啊!应该是:int i=Integer.parseInt(“”+request.getParameter())就可以了
      

  5.   

    baokuijian(阿包):
    request.getParameter()得到的本来就是String
      

  6.   

    int i=Integer.parseInt(request.getParameter());
      

  7.   

    标准做法:
    int i=0;
    try {i=Integer.parseInt(request.getParameter());
    }
    catch(NumberFormatException e)
    {//i=0;
    }
      

  8.   

    原来是传过来的是'6'而不是6,谢谢大家了不过用int i=Integer.parseInt(""+request.getParameter());的话报这个错误
    java.lang.NumberFormatException: For input string: "null"值为:
    s=7
    i=0怎样才能转换成String呢
      

  9.   

    String s=request.getParameter();
    if(s!=null && s 是数值){
    i=Integer.parseInt(s);
    }
      

  10.   

    int i=Integer.parseInt(request.getParameter());
      

  11.   

    根本没有request.getParameter()这个方法getParameter必须放个String做为参数的楼主是不是搞错了
      

  12.   

    标准做法:
    int i=0;
    try {i=Integer.parseInt(request.getParameter());
    }
    catch(NumberFormatException e)
    {//i=0;
    }NumberFormatException 属于非检查性异常,就是说不需要你自己去try catch.
    并且即使一旦出现这种异常,也认为是设计错误,是程序员的责任,是可以避免的,例如在把参数传进你的方法前,先判断参数是否为数字。如果因为不是数字而产生了NumberFormatException,说明你程序的CHECK PARAMETER的工作没做好,是你的责任。
      

  13.   

    request.getParameter()出来是'6'的话,这是个string,先处理这个string变成6,再Integer.parseInt就行了吧
      

  14.   

    int i=Integer.parseInt(request.getParameter("parm").toString());
      

  15.   

    int i=(int)request.getParameter("parm")
      

  16.   

    Top  
     langke93(冬会初雪) ( ) 信誉:100  2006-8-7 18:58:06  得分: 0     
    int i=Integer.parseInt(request.getParameter("parm").toString());
    ----------------------------------------------------------
      我也觉得应该这样(如果得到的不是String类型的话)
     
      

  17.   

    int i=Integer.parseInt(request.getParameter()+"");
      

  18.   

    Integer.parseInt(request.getParameter("id").ToString().Replace("'",""));
      

  19.   

    String temp = request.getParameter("id");
    int id = 0;
    if(temp != null && !temp.equals("")){
      id = Integer.parseInt(temp);
    }
    如果你还想验证传过来的参数是int.
    则可以通过此来验证;不建议通过异常来做判断; /**
     * Check whether the string is an integer.
     * @param s
     * @return boolean
     * @author Jason Cheng
     */
    public static final boolean isInteger(final String str) {
    if (isEmpty(str)) {
    return false;
    }
    for (int x = 0; x < str.length(); x++) {
    final char c = str.charAt(x);
    /* negative */
    if (x == 0 && (c == '-')) {
    continue;
    }
    /* 0 - 9 */
    if ((c >= '0') && (c <= '9')) {
    continue;
    }
    /* invalid */
    return false;
    }
    /* valid */
    return true;
    } /**
     * Check whether the string is not empty.
     * @param str
     * @return boolean
     * @author Jason Cheng
     */
    public static final boolean isEmpty(String str) {
    return (str == null) ? true : (str.trim().length() == 0);
    }