开发者

Problem with parsing String convertion to int in java

Please help me for conversion my line of codes are mention below:

String deptName = "IT";
String dept_test = request.getParameter("deptName").trim();
System.out开发者_StackOverflow.println("Dept name vlue is"+dept_test);
// problem here for casting...
int dept_id = Integer.parseInt(dept_test);


I don't see any casting problems. If your text doesn't contain a parseable number you will get a NumberFormatException which you may need to catch with a try/catch block. What exactly is the problem you are having?


From looking at your code the most you get will be an error parsing the input (including if it is none. What may be an issue is that the variable deptName is never used. Did you mean to make the second line

String dept_test = request.getParameter(deptName).trim();

(notice no quotes) instead?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜