JSP Integer.parseInt

时间:2011-11-28 05:21:44

标签: jsp

我正在尝试在JSP页面中将String转换为Integer。我在转换时遇到运行时错误。当我删除它下面的2行时,temp[0]完全显示5。这是我的示例代码:

<%@ page import = "java.util.*"%>
<%@ page import = "java.lang.*"%>
<% String name = "5.ACC";
   String temp[] = name.split("\\.");
   out.println(temp[0]); 
   int id = Integer.parseInt(temp[0]);
   out.println(id);
%>

1 个答案:

答案 0 :(得分:0)

有了这些信息。觉得你可以使用temp [0]·trim()来避免数字格式异常。