日期:2014-05-18  浏览次数:20711 次

请大家帮我看看,这个程序为什么报错?关于Integer.parseInt的~!
这个程序非常非常的简单,是关于跳转页面的。
第一个程序:
<%@   page   contentType= "text/html;charset=gb2312 "   %>
<html>
<head>
<title> JSP读页id实验页面 </title>
</head>
<body>
请选择点击一页: <br> <br>
<a   href=chaiao_10_2.jsp?id=1> 转到第一页 </a> <br>
<a   href=chaiao_10_2.jsp?id=2> 转到第二页 </a> <br>
<a   href=chaiao_10_2.jsp?id=3> 转到第三页 </a> <br>
<a   href=chaiao_10_2.jsp?id=4> 转到第四页 </a> <br>
<a   href=chaiao_10_2.jsp?id=5> 转到第五页 </a>
</body>
</html>

第二个:
<%@   page   contentType= "text/html;charset=gb2312 "   %>
<%@   page   import= "java.io.* "   %>
<html>
<head>
<title> 显示适当的页数 </title>
</head>
<body>
<%
String   i=request.getParameter( "id ");
int   page=Integer.parseInt(i);
out.println( "这是第 "+page+ "页。 ");
%>
</body>
</html>
它就是出错!报错为:
org.apache.jasper.JasperException:   Unable   to   compile   class   for   JSP:  

An   error   occurred   at   line:   11   in   the   jsp   file:   /chaiao/chaiao_10_2.jsp
Duplicate   local   variable   page
8:   <%
9:   String   i=request.getParameter( "id ");
10:   //注意,id是字符串,而不是int。
11:   int   page=Integer.parseInt(i);
12:   out.println( "这是第 "+page+ "页。 ");
13:   %>
14:   </body>

请问这是为什么??
(我知道不把它转为int也可以,但小弟非常好奇这个为什么错了??!!)
谢谢!!!!!!

------解决方案--------------------
int page=Integer.parseInt(i);
这里的变量page不合法
改成其他的如pageId就可以了
------解决方案--------------------
把 i 现打出来,别转换看看。
------解决方案--------------------
因为JSP里面有个内置变量就叫page,所以,你不能再定义叫page的变量了
------解决方案--------------------
zqrqq(zqrain(结帖是一种美德))

正解,

偶 有时也出这个错,比如 session, application ,这些变量你都不能用,这是JSP的内置变量

------解决方案--------------------
把转换的地方try/catch一下.
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.aiyiweb.com/j2ee/2308.html