我在修改密码页面下:
<%@include file="inc/dbsfunc.jsp"%>
<font color="#FF3300">级别:</font></font></font> <font color="#006699"><%=GetGradeName(session.getAttribute("grade"));%>提示这个错误:Syntax error on token ";", delete this token
inc/dbsfunc.jsp页面下的类:
     class myFunction{  
      //取得设备名称
        void GetDevName(Object DeviceId){
           String GetDevName;
           Statement st_DeviceCode;
           st_DeviceCode=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
           String sql_DeviceCode="select count(*) coun from DeviceCode where DeviceId like'"+Trim(DeviceId) +"'" ;
           ResultSet rs_DeviceCode=st_DeviceCode.executeQuery(sql_DeviceCode);
           int Count=rs_DeviceCode.getInt(coun);
           if(Count>0)
                 GetDevName =( "未知设备(" + DeviceId + ")");
           else
                 GetDevName = Trim(rs_DeviceCode("DeviceName"));               
           rs_DeviceCode.close();
      }
  }
提示:Cannot refer to a non-final variable conn inside an inner class defined in a 
 different method不知道错在哪,刚接触JSP  请大家指教下怎么修改

解决方案 »

  1.   

    你这句话<%=GetGradeName(session.getAttribute("grade"));%>
    末尾的;去掉试试...
      

  2.   

    同意楼上。
    <%=%>这里面存放的是一个变量,不是一个语句,不要;结尾
      

  3.   

    Cannot refer to a non-final variable conn inside an inner class defined in a different method.
    myFunction是不是内部类呢,内部类调用conn,conn需要改成final,字面应该是这个意思。
      

  4.   

    很明显你脚本段里面<%=.....%>里面的分号是不需要的!
      

  5.   


    谢谢大家,但是我分号去掉后,出现了很多
    Statement cannot be resolved to a type cannot be resolved to a type basePath cannot be resolved
      

  6.   


    换了后 提示
    Syntax error on token "final", invalid Expression
      

  7.   

    <%=GetGradeName(session.getAttribute("grade"));%>删除“”号
    写成<%= xxxx%>的时候  末尾不用加“;”号
    Statement cannot be resolved to a type  cannot be resolved to a type  basePath cannot be resolved这些应该都是没有导入包引起的、  statement是java.sql的statement吗?
    basePath 应该是没定义、楼主没有ide吗?你还是把全部代码贴出来吧、我们也好查看下哪里引起的、最好贴上代码格式、
      

  8.   

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ include file="../dbsconn.jsp"%>
    <%@page import="java.sql.*,java.lang.*,java.io.*"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title></title>
        
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->  </head>
      <%
         Statement st_TradeDB;
         st_TradeDB=conn.createStatement();
          String SQL_sub0="";
          String SQL_sub="";
          String SQL_Join_sub="";
          String SQL_Join_sub0="";
          if(session.getAttribute("BranchId")=="-1"){
                 SQL_sub = "  ";
                 SQL_Join_sub0="";
                 }
          else{
             SQL_sub = " and BranchId='" +session.getAttribute("BranchId") + "' and NodeId='" + session.getAttribute("NodeId") + "' ";
             SQL_sub0 = " where BranchId='" + session.getAttribute("BranchId") + "' and NodeId='" + session.getAttribute("NodeId") + "' ";
             SQL_Join_sub = " and TermInfo.BranchId='" +session.getAttribute("BranchId") + "' and TermInfo.NodeId='" + session.getAttribute("NodeId") + "' ";
             SQL_Join_sub0 = " where TermInfo.BranchId='" + session.getAttribute("BranchId") + "' and TermInfo.NodeId='" + session.getAttribute("NodeId") + "' ";
          }
         
         int SysFunction = 0;
         int DelFunction=0;
         int SearchFunction=0;
         int UpdateFunction=0;
         int AddFunction=0;
         
         if("".equals(((String)session.getAttribute("grade")).trim())){
             SearchFunction=1;
             if("1".equals(((String)session.getAttribute("grade")).trim())&&"-1".equals(((String)session.getAttribute("BranchId")).trim())){
               DelFunction=1;
               AddFunction=1;
                UpdateFunction=1;
                
              } 
           if("0".equals(((String)session.getAttribute("grade")).trim()))
           {
               SysFunction = 1;
               DelFunction=1;
               AddFunction=1;
               UpdateFunction=1;
            }
          }
         class myFunction{  
          //取得设备名称
            void GetDevName(Object DeviceId){
               String GetDevName;
               Statement st_DeviceCode;
               st_DeviceCode=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
               String sql_DeviceCode="select count(*) coun from DeviceCode where DeviceId like'"+Trim(DeviceId) +"'" ;
               ResultSet rs_DeviceCode=st_DeviceCode.executeQuery(sql_DeviceCode);
               int Count=rs_DeviceCode.getInt(coun);
               if(Count>0)
                     GetDevName =( "未知设备(" + DeviceId + ")");
               else
                     GetDevName =trim(rs_DeviceCode.getString("DeviceName"));               
               rs_DeviceCode.close();
          }
      }
       %>
      <body> 
      test 
      </body>
    </html>提示的是:
    Cannot refer to a non-final variable conn inside an inner class defined in a 
     different methodcoun cannot be resolvedThe method trim(String) is undefined for the type myFunction  这三个错误
      

  9.   

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@include file="inc/dbsfunc.jsp"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title></title>
        
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <% 
     if(SearchFunction==0){
       out.println("<SCRIPT language='JavaScript'>");
       out.println("alert('已经超时,请退出重新登录');"); 
       out.println("javascript:history.go(-1)");
       out.println("</SCRIPT>");   
       out.close();
    }
    %>
    <script language="JavaScript">   
      function del_confirm(UserStr)   
      {   
      if(confirm("确定修改密码吗?")==true)   
      {   
         top.frames(2).location.href="ChangePasswd.jsp?Function=1&OldPasswd="+ OldPasswd.value;  
      }
      return;   
      }   
     </script>
    </head>
    <%
      //Function = ""  显示
      //        = 1 修改密码
       
      if(request.getParameter("Function")=="1")
       {
          if(request.getParameter("NewPasswd1")!=(request.getParameter("NewPasswd2"))){
               response.sendRedirect("fail.jsp?Str=两次密码不一致,请重新输入");}
             
        }
         Statement st;
         st=conn.creatmente();
         String Sql="Select count(*)coun from UserT where UserName like'" + session.getAttribute("UserName") + "' and Password like'" + request.getParameter("OldPasswd") + "'";
         ResultSet rs=st.executeQuery(Sql);
         while(rs.next()){
               rs.close();
               st.close();
               Statement st2;
               String sql="UPDATE UserT Set Password='" + request.getParameter("NewPasswd1") + "' where UserName like'" + session.getAttribute("UserName") + "'"; 
               ResultSet rs2=st2.executeQuery(Sql);
              // WriteLogDB("修改密码成功,用户号:"& Session("UserName"))
               String SQL="insert into UserOpert(UserName,Operation,grade) Values('"+session.getAttribute("UserName")+"','修改密码','"+session.getAttribute("grade")+"')";
               Boolean bool;
               bool=st2.execute(SQL);
               if(bool)
                response.sendRedirect("fail.jsp?Str=密码修改成功");
                else
                response.sendRedirect("fail.jsp?Str=原密码错误");
      }
    %><body topmargin="0" leftmargin="0" bgcolor="#EBF7FC">
    <SCRIPT language=JavaScript src="inc/window.js"></SCRIPT>
    <SCRIPT language=VbScript ></SCRIPT>
    <div align="center"><br>
      <table border=0 cellpadding=0 cellspacing=0 width="98%" align="center">
        <tbody> 
        <tr> 
          <td bgcolor=#0066CC height=30 width="42%"> 
            <table align=center bgcolor=#000000 border=0 cellpadding=1 
                cellspacing=1 width="98%">
              <tbody> 
              <tr bgcolor="#ffffff"> 
                <td> 
                  <div align=center><font color="#FF3300">当前操作员:<font color="#006699"><%out.println(session.getAttribute("UserName"));%>
                     <font color="#FF3300">级别:</font></font></font> <font color="#006699"><%=GetGradeName(session.getAttribute("grade"))%>
                        
                     </font></div>
                </td>
              </tr>
              </tbody> 
            </table>
          </td>
          <td bgcolor=#FFFFFF width="58%"> 
          </td>
        </tr>
        </tbody> 
      </table>
      <form method="post" action="ChangePasswd.asp?Function=1" name="ChangePasswd">
        <p>&nbsp;</p>
        <table border="1" cellpadding="0" cellspacing="0" width="500" bordercolor="#FFFFFF" bordercolorlight="#8bb9fa" bordercolordark="#FFFFFF" align="center">
          <tr > 
            <td width="83%" height="18" valign="bottom" background="images/admin_bg_1.gif"> 
              <div align="center"><font color="#FFFFFF">[修改密码]&nbsp;</font></div>
            </td>
          </tr><tr align="Center"> 
            <td height="6" valign="bottom">
      
              <p>旧&nbsp;密&nbsp;码:
                <input type="text" name="OldPasswd">
              </p>
              <p>新&nbsp;密&nbsp;码:
                <input type="text" name="NewPasswd1">
              </p>
              <p>确认密码:
                <input type="text" name="NewPasswd2">
              </p>
              <p>
                <input  type="submit" name="Submit" value="修改密码" onClick="del_confirm(OldPasswd.value)">
              </p>
              <p>&nbsp;          </p>
              <font color="#000000"> </font></td>
          <tr> 
            <td height="2" valign="top" bgcolor="#000000"> </td>
          </tr>
        </table>
        <br>
    <tr align="center"></tr>  </form>  <p>&nbsp;</p>
      <p><font color="#000000"></font></p>
    </div>
    </body></html>
    提示的:Multiple annotations found at this line:
    - conn cannot be resolved
    - The method trim(String) is undefined for the type myFunction
    - coun cannot be resolved
    - The method Trim(Object) is undefined for the type myFunctionbasePath cannot be resolved
    conn cannot be resolvedThe method GetGradeName(Object) is undefined for the type 
     __2F_ChenTong_2F_WebRoot_2F_ChangePasswd_2E_jsp    四个错误
      

  10.   

    <%=GetGradeName(session.getAttribute("grade"));%>
    楼主把后面的";" 去掉就ok了!
      

  11.   

         class myFunction{  
          //取得设备名称
            void GetDevName(Object DeviceId){
               String GetDevName;
               Statement st_DeviceCode;
               st_DeviceCode=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
               String sql_DeviceCode="select count(*) coun from DeviceCode where DeviceId like'"+Trim(DeviceId) +"'" ;
               ResultSet rs_DeviceCode=st_DeviceCode.executeQuery(sql_DeviceCode);
               int Count=rs_DeviceCode.getInt(coun);
               if(Count>0)
                     GetDevName =( "未知设备(" + DeviceId + ")");
               else
                     GetDevName =trim(rs_DeviceCode.getString("DeviceName"));               
               rs_DeviceCode.close();
          }
      }coun 没有定义 conn没有定义,估计是<%@include file="inc/dbsfunc.jsp"%>未引入,或者是这个jsp本身就有问题
      

  12.   

    <%@ include file="../dbsconn.jsp"%>注意路径
      

  13.   

    看楼主的写法太像phper了、这看的我都有点蒙了、
    1、你居然在jsp里写class。这就是内部类的错误原因了、jsp最终会被编译成class文件的、
    你还是把这个定义的myFunction class拿出来去该写的地方写吧、而且看这个写法完全可以抽取成公用的、2、 你自己的方法?这是去空格吗?
    rs_DeviceCode.getString("DeviceName").trim();---------------------------------------------以上是11楼、以下是12楼--------------------
    conn cannot be resolved 我真在你的jsp代码里没有找到你定义好的connection类型 并且变量为conn 
    - The method trim(String) is undefined for the type myFunction  你的类myFunction 里面有trim(String)方法吗?你自己定义过吗?- coun cannot be resolved  coun 这又是个什么意思呢?看你的语句int Count=rs_DeviceCode.getInt(coun);
      应该是获取某一行、请问表的列字段名字叫什么?或者是第几个列?
      int Count=rs_DeviceCode.getInt(1); //获取第一个列的值
      int Count=rs_DeviceCode.getInt("1");//获取列名为1的值- The method Trim(Object) is undefined for the type myFunction   你的类myFunction 里面有Trim(Object)方法吗?你自己定义过吗?
      

  14.   

    还有你是否有已经抽取公用的connection类?那你要获取起码也得定义conn的类型吧?Connection conn = DBuitls.getConnection();//比如从某个公用类中获取connection连接然后你才能用吧?java是需要先定义后才能使用的、
      

  15.   


    谢谢你这么详细的回答
    JSP页面下加<%%>不就是JAVA吗?  里面不能写类?  本来是想把第一个页面的GetDeviceID当成参数传过去
    然后数据库查询到ID相应的设备
    定义statement  st;  st不是有个conn对象? 
      

  16.   

    <%=GetGradeName(session.getAttribute("grade"));%>
    我分析了一下void GetDevName(Object DeviceId)这个方法没有返回值,你为什么要用<%=%>
    如果想单纯的调用GetDevName。我建议你去掉“=”
    最终建议:
    <%GetGradeName(session.getAttribute("grade"));%>ps:java方法名称,第一个字母应该是小写的吧。编码规范的说。。