一个jsp页面连接数据库问题
小弟在写jsp连接数据库页面时,出现了一个很想不同的问题,我的jsp源代码如下:
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String user = "root";
String password = "root";
String sql = "select * from bbs_uploadfile";
try{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/yhbbs";
conn = DriverManager.getConnection(url,user,password);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
} catch(Exception e) {
e.printStackTrace();
}
%>
<form id="form1" name="form1" method="post" action="do_downfile.jsp">
<%
if(rs != null) {
System.out.println("ok");
try{
while(rs.next) {
out.println("<TABLE BORDER=1>");
out.println("<TR><TD>" + rs.getString("filename") + "</TD><TD>查看</TD></TR>");
out.println("</TABLE><BR>");
}
} catch(Exception e) {
e.printStackTrace();
}
}
%>
我在tomcat运行出现的错误如下,
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 33 in the jsp file: /downloadfile.jsp
rs.next
cannot be resolved or is not a field
30: if(rs != null) {
31: System.out.println("ok");
32: try{
33: while(rs.next) {
34: out.println("<TABLE BORDER=1>");
35: out.println("<TR><TD>" + rs.getString("filename") + "</TD><TD>查看</TD></TR>");
36:
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:93)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:435)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
这个错误是什么,麻烦高手们帮我解答一下,是什么意思,问题怎么解决,小弟在此感激不尽………………
------解决方案--------------------
rs.next()
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.aiyiweb.com/j2ee/2308.html