我写了一个HTML代码在JSP中,是一个form表单,可以提交到数据库,而我用doget方法把年龄读出来了,但是之前我在JAVA中定义的是int型,而从html中取到doget中时,是string型,想到这个String型的数字存到之前我定义的那个INT型的变量中,我应该如何改换类型 呢?protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
String age = request.getParameter("age");
String interesting = request.getParameter("interesting");
String description = request.getParameter("description");



Cotroller oneCotroller = new Cotroller();//定义一个Cotroller类的oneCotroller变量,那么这个oneCotroller就可以调用Cotroller中的方法。

Userinformation userinformation = new Userinformation();
userinformation.setUsername(username);
userinformation.setPassword(password);
userinformation.setAge(age)
//这个地方有错,
The method setAge(int) in the type Userinformation is not applicable for the arguments (String) myfirtweb/src/com/qinghe/test ZHUCE.java line 48 1215662941843 877     userinformation.setInteresting(interesting);
谢谢前辈们指点!

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【chenlei8812】截止到2008-07-10 12:21:56的历史汇总数据(不包括此帖):
    发帖的总数量:3                        发帖的总分数:80                       每贴平均分数:26                       
    回帖的总数量:3                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:3                        结贴的总分数:80                       
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:0                        未结的总分数:0                        
    结贴的百分比:100.00%               结分的百分比:100.00%                  
    无满意结贴率:0.00  %               无满意结分率:0.00  %                  
    敬礼!
      

  2.   

    int age = Integer.parseInt(request.getParameger("age"));
      

  3.   

    String s = request.getParameger("age");
    int age = (s == null) ? 0 : Integer.parseInt(s);
      

  4.   

    int age = Integer.parseInt(request.getParameger("age"));
      

  5.   

        public static int parseInt(String s, int radix)
    throws NumberFormatException
        {
            if (s == null) {
                throw new NumberFormatException("null");
            } if (radix < Character.MIN_RADIX) {
        throw new NumberFormatException("radix " + radix +
        " less than Character.MIN_RADIX");
    } if (radix > Character.MAX_RADIX) {
        throw new NumberFormatException("radix " + radix +
        " greater than Character.MAX_RADIX");
    } int result = 0;
    boolean negative = false;
    int i = 0, max = s.length();
    int limit;
    int multmin;
    int digit; if (max > 0) {
        if (s.charAt(0) == '-') {
    negative = true;
    limit = Integer.MIN_VALUE;
    i++;
        } else {
    limit = -Integer.MAX_VALUE;
        }
        multmin = limit / radix;
        if (i < max) {
    digit = Character.digit(s.charAt(i++),radix);
    if (digit < 0) {
        throw NumberFormatException.forInputString(s);
    } else {
        result = -digit;
    }
        }
        while (i < max) {
    // Accumulating negatively avoids surprises near MAX_VALUE
    digit = Character.digit(s.charAt(i++),radix);
    if (digit < 0) {
        throw NumberFormatException.forInputString(s);
    }
    if (result < multmin) {
        throw NumberFormatException.forInputString(s);
    }
    result *= radix;
    if (result < limit + digit) {
        throw NumberFormatException.forInputString(s);
    }
    result -= digit;
        }
    } else {
        throw NumberFormatException.forInputString(s);
    }
    if (negative) {
        if (i > 1) {
    return result;
        } else { /* Only got "-" */
    throw NumberFormatException.forInputString(s);
        }
    } else {
        return -result;
    }
        }    public static int parseInt(String s) throws NumberFormatException {
    return parseInt(s,10);
        }
      

  6.   

    这次下面的age是没有问题了,可是我加进去的那句int age = Integer.parseInt(request.getParameter("age"));又出了问题:Severity and Description Path Resource Location Creation Time Id
    Duplicate local variable age myfirtweb/src/com/qinghe/test ZHUCE.java line 38 1215665734265 885
      

  7.   

    谢谢模拟人生,是我把两个age弄重了,现在修改好了,这个问题解决了!
      

  8.   

    你的age重复定义了,你把前面的age定义称strAge,后面的定义称age不就行了吗