源代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"%>
<%@ include file="conn.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>注册资料修改初步</title>
</head>
<body>
<%
String userid=(String)session.getAttribute("submit");
String sqlStr="select * from young where userid='"+userid+"'";
ResultSet rs=stmt.executeQuery(sqlStr);
if (rs.next())
{
String pwd=(String)rs.getString("pwd");
String email=(String)rs.getString("email");
}
%>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="4">
<form method="post" name="frm1" action="modify.jsp">
<tr>
<td align="center">用户名:
<input type="text" name="userid" readonly="true" value="<%=userid%>"></td>
</tr>
<tr>
<td align="center">密码:
<input type="text" name="pwd" value="<%=pwd%>"></td>
</tr>
<tr>
<td align="center">email:
<input type="text" name="email" value="<%=email%>"></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="提交"></td>
</tr>
</form>
</table>
<%
stmt.close();
conn.close();
%>
</body>
</html>
运行错误如下:
HTTP Status 500 -
--------------------------------------------------------------------------------type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 29 in the jsp file: /bbs/login/modify.jsp
Generated servlet error:
C:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\bbs\login\modify_jsp.java:94: cannot resolve symbol
symbol : variable pwd
location: class org.apache.jsp.bbs.login.modify_jsp
out.print(pwd);^An error occurred at line: 33 in the jsp file: /bbs/login/modify.jsp
Generated servlet error:
C:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\bbs\login\modify_jsp.java:100: cannot resolve symbol
symbol : variable email
location: class org.apache.jsp.bbs.login.modify_jsp
out.print(email); ^2 errors
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
我能确定:session那边没有问题,因为如果我把pwd和email注释掉后,userid能够显示。
參考答案:String pwd=(String)rs.getString("pwd");
String email=(String)rs.getString("email");
这两个变量的声明要放到if的外面,放里面外面当然不认pwd,email变量了