日期:2014-05-17  浏览次数:20570 次

JSP下session传值问题 先谢谢了!
我在修改密码页面下:
<%@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 请大家指教下怎么修改

------解决方案--------------------
很明显你脚本段里面<%=.....%>里面的分号是不需要的!
------解决方案--------------------
java表达式里面不需要分号
------解决方案--------------------
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本身就有问题
------解决方案--------------------
看楼主的写法太像phper了、这看的我都有点蒙了、

探讨

Java code
<%@ 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//……

------解决方案--------------------
<%=GetGradeName(session.getAttribute("grade"));%>
我分析了一下void GetDevName(Object DeviceId)这个方法没有返回值,你为什么要用<%=%>
如果想单纯的调用GetDevName。我建议你去掉“=”
最终建议:
<%GetGradeName(session.getAttribute("grade"));%>

ps:java方法名称,第一个字母应该是小写的吧。编码规范的说。。。。。