变量问题
if(!schuid.equals( " "))
{
sql= "select * from usertab where userid= ' "+schuid+ " ' ";
ResultSet urs=lgst.executeQuery(sql);
if(urs.next())
{
g=true;///21行;
}
}
if(g)
{
session.setAttribute( "srs ",urs);
}
报错如下:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 11 in the jsp file: /biye/bank/search2.jsp
Generated servlet error:
C:\jakarta-tomcat-5.0.28\work\Catalina\localhost\_\org\apache\jsp\biye\bank\search2_jsp.java:109: cannot resolve symbol
symbol : variable urs
location: class org.apache.jsp.biye.bank.search2_jsp
session.setAttribute( "srs ",urs);
我把session.setAttribute( "srs ",urs);放在换21行就没问题?为什么呀??
[解决办法]
urs变量的作用范围
[解决办法]
按照LZ那样写,urs的范围仅仅适用于第一个if判断,当然第二个if不能获取了
[解决办法]
解决的方法有很多,我建议单独提取g出来,
可以这样
boolean g = false;
if(!schuid.equals( " ")){内容不变}
if(g){内容不变}
[解决办法]
sql= "select * from usertab where userid= ' "+schuid+ " ' ";
ResultSet urs=lgst.executeQuery(sql);
把这两句也单独提出来
[解决办法]
主要是要解决urs的问题
独立出来的urs,这样2个if都可以调用
[解决办法]
突然发现独立出来
sql= "select * from usertab where userid= ' "+schuid+ " ' ";
ResultSet urs=lgst.executeQuery(sql);
后,第一个if貌似没有意义了,还是把第2个if嵌入第1个if吧
if(!schuid.equals( " "))
{
sql= "select * from usertab where userid= ' "+schuid+ " ' ";
ResultSet urs=lgst.executeQuery(sql);
if(urs.next())
{
g=true;///21行;
}
if(g)
{
session.setAttribute( "srs ",urs);
}
}
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html