JSP问题请教!!!我不明白为什么老是出错?

来源:百度知道 编辑:UC知道 时间:2024/06/10 01:36:31
出错提示:org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 16 in the jsp file: /SimpleLoading/index.jsp
isLog cannot be resolved
13: <% try{boolean isLog=false;
14: isLog=((String)session.getAttribute("isLog")).equals("1");
15: }catch(Exception e){}
16: if(isLog){
17: %><a href="logout.jsp">注销</a>::<br><hr>
18: 欢迎光临!<%=session.getAttribute("userName")%>您是第<%=session.getAttribute("userLogCount")%>次登录,你上次登录的时间是:<%=session.getAttribute("userLastLogTime")%><hr>
19: <%}

<%@ page contentType="text/html;charset=GB2312" language="java"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org

你的变量isLog是定义在try catch块里面的,那么他的范围自然是只在try{}
这两个大括号里面, 而你在try catch外面又去用它,自然编译器就不认识它了,就是局部变量作用域的问题,所以说isLog cannot be resolved ,翻译过来就是islog不能被识别,在第16行,提示的这么明显了,即使英语不好,也要学会看提示啊。

你只要在try外面先定义一下就行了

这是一个变量的作用域问题,你的isLog变量的作用域只在try{}里,在这个作用域外使用它就是无法识别。在try{}外加上boolean isLog=false; 这样就行了。