关于JSP页面抱错找不到符号求救啊
小弟运行这段JSP代码总抱错找不到符号 大家指点下啊谢谢啦
<%@ page contentType= "text/html;charset=gb2312 "%>
<table width= "180 " height= "18 " border= "0 " cellpadding= "0 " cellspacing= "0 ">
<form method= "POST " action= "login.jsp ">
<%
//是否登陆
if((String)session.getValue( "user_name ")!=null)
{
String name=(String)session.getAttribute( "user_name ");
sql= "select * from member where user_name= ' "+name+ " ' ";
rs=stmt.executeQuery(sql);
if(rs.next()){
%>
<tr align= "justify " valign= "top ">
<td width= "120 " height= "20 "> 用户名: </td>
<td width= "51 " height= "20 "> <%=rs.getString
( "user_name ")%> </td>
</tr>
<tr>
<td height= "25 "> 地址: </td>
<td height= "25 "> </td>
</tr>
<tr>
<td height= "25 "
colspan= "2 "> <div align= "center "> <a href= "index.jsp?loginout=true "> 退出登录 </a> </div>
</td>
</tr>
<%
}
}else
//没有登陆
{
%>
<tr>
<td> <div align= "center "> 客户: </div> </td>
<td> <div align= "center ">
<input name= "user_name " type= "text " class=input id= "user_name "
style= "FONT-SIZE: 12px; WIDTH: 110px " size= "10 " maxlength= "18 ">
</div> </td>
</tr>
<tr>
<td> <div align= "center "> 密码: </div> </td>
<td> <div align= "center ">
<input style= "FONT-SIZE: 12px; WIDTH: 110px "
type= "password " name= "user_pass " size= "10 " class=input maxlength= "18 ">
</div> </td>
</tr>
<tr>
<td colspan= "2 " nowrap> <div
align= "center ">
<input type= "submit " name= "Submit2 " value= "登录 ">
<input type= "button " name= "Submit " value= "用户注册 "
onClick= "javascript:window.location.href= 'reguser.jsp ' ">
</div> </td>
</tr>
<%
}//判断登陆结束
String loginout=request.getParameter( "loginout ");//退出登陆
if(loginout!=null)
{
if(loginout.compareTo( "true ")==0)
{
session.removeAttribute( "user_name ");
response.sendRedirect( "index.jsp ");
}
}
%>
</form>
</table>
<p> </p>
抱错信息是:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 4 in the jsp file: /denglu.jsp
Generated servlet error:
D:\eclipse\workspace\tushu\work\org\apache\jsp\denglu_jsp.java:50: 找不到符号
符号: 变量 sql
位置: 类 org.apache.jsp.denglu_jsp
sql= "select * from member where user_name= ' "+name+ " ' ";
^
An error occurred at line: 4 in the jsp file: /denglu.jsp
Generated servlet error:
D:\eclipse\workspace\tushu\work\org\apache\jsp\denglu_jsp.java:51: 找不到符号
符号: 变量 rs
位置: 类 org.apache.jsp.denglu_jsp
rs=stmt.executeQuery(sql);
^
An error occurred at line: 4 in the jsp file: /denglu.jsp
Generated servlet error:
D:\eclipse\workspace\tushu\work\org\apache\jsp\denglu_jsp.java:51: 找不到符号
符号: 变量 sql
位置: 类 org.apache.jsp.denglu_jsp
rs=stmt.executeQuery(sql);
^
An error occurred at line: 4 in the jsp file: /denglu.jsp
Generated servlet error:
D:\eclipse\workspace\tushu\work\org\apache\jsp\denglu_jsp.java:51: 找不到符号
符号: 变量 stmt
位置: 类 org.apache.jsp.denglu_jsp
rs=stmt.executeQuery(sql);
^
An error occurred at line: 4 in the jsp file: /denglu.jsp
Generated servlet error:
D:\eclipse\workspace\tushu\work\org\apache\jsp\denglu_jsp.java:52: 找不到符号
符号: 变量 rs
位置: 类 org.apache.jsp.denglu_jsp
if(rs.next()){
^
An error occurred at line: 15 in the jsp file: /denglu.jsp
Generated servlet error:
D:\eclipse\workspace\tushu\work\org\apache\jsp\denglu_jsp.java:58: 找不到符号
符号: 变量 rs
位置: 类 org.apache.jsp.denglu_jsp
out.print(rs.getString( "user_name "));
^
注意:D:\eclipse\workspace\tushu\work\org\apache\jsp\denglu_jsp.java 使用或覆盖了已过时的 API。
注意:要了解详细信息,请使用 -Xlint:deprecation 重新编译。
小弟接触JSP时间不长 不知道这问题从哪下手啊
[解决办法]
sql= "select * from member where user_name= ' "+name+ " ' ";
找不到sql,你没有声明这个字符串,虽然在JAVA中编译器遇到 " "中的内容都会作为一个字符串来处理,但是确实编译器找不到叫做sql的字符串,
[解决办法]
sql是哪来的,没有声明吧。
把sql= "select * from member where user_name= ' "+name+ " ' ";
改成String sql= "select * from member where user_name= ' "+name+ " ' ";
[解决办法]
晕,都告诉说未定义sql变量了还不知道怎么改。。。
[解决办法]
先定义,再使用,养成良好的习惯,HOHO
[解决办法]
你的变量sql、rs、stmt 都没有定义,而且没有引入包java.sql.*
文件头上应该是
<%@ page contentType= "text/html;charset=gb2312 "%>
<%@ page import= "java.sql.*>
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html