怎么在jsp中转换int类型

2024-11-17 04:30:07
推荐回答(3个)
回答1:

String chushu = request.getParameter("chushu");
String beichushu = request.getParameter("beichushu");
int he=Integer.parseInt(chushu)+Integer.parseInt(beichushu) ;
在程序中(非jsp页面)我们一般习惯用try ...catch包起来 因为怕chushu或beichushu有null;
所以程序中
String chushu = request.getParameter("chushu");
String beichushu = request.getParameter("beichushu");
try{
int he=Integer.parseInt(chushu)+Integer.parseInt(beichushu) ;
}catch(Exception e){
System.out.println(e.getMessage());
}

回答2:

String chushu = request.getParameter("chushu");
int c = Integer.parseInt(chushu);

回答3:

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