读书人

新手请问SWITCH有关问题

发布时间: 2013-09-11 18:34:25 作者: rapoo

新手请教SWITCH问题
麻烦大家给看看下面这段程序那里有问题,谢谢!
注:数据库中数据类型为int;

<%
String img= " ";
ResultSet rs_zt=stmt.executeQuery( "select * from zt where ProjectID= ' "+temp+ " ' ");
while(rs_zt.next()){
int tmpx=rs_zt.getInt( "xqfx_zt ");
}
switch(tmpx){
case 0:img= "images/0.gif ";
break;
case 1:img= "images/1.gif ";
break;
default:img= "images/2.gif ";
break;
}
%>

错误提示为:

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 115 in the jsp file: /detail.jsp
tmpx cannot be resolved
112: while(rs_zt.next()){
113: int tmpx=rs_zt.getInt( "xqfx_zt ");
114: }
115: switch(tmpx){
116: case 0:img= "images/0.gif ";
117: break;
118: case 1:img= "images/1.gif ";


[解决办法]
while(rs_zt.next()){
int tmpx=rs_zt.getInt( "xqfx_zt ");
}

超过这个范围 tmpx的生命周期已经结束 所以找不到tmpx 如果你希望用到这个
要么吧switch部分代码放到while里面 要么吧tmpx的定义放到while外面
[解决办法]

<%
String img= " ";
ResultSet rs_zt=stmt.executeQuery( "select * from zt where ProjectID= ' "+temp+ " ' ");
while(rs_zt.next()){
int tmpx=rs_zt.getInt( "xqfx_zt ");
switch(tmpx){
case 0:img= "images/0.gif ";
break;
case 1:img= "images/1.gif ";
break;
default:img= "images/2.gif ";
break;
}

}

%>


我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html

读书人网 >Java Web开发

热点推荐