一个JSP小程序,不知道是哪里出错了,请大家帮帮忙~~
报错内容:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 2 in the jsp file: /addke.jsp
Generated servlet error:
Int cannot be resolved or is not a type
An error occurred at line: 2 in the jsp file: /addke.jsp
Generated servlet error:
Incompatible operand types ResultSet and int
An error occurred at line: 2 in the jsp file: /addke.jsp
Generated servlet error:
rs cannot be resolved
An error occurred at line: 2 in the jsp file: /addke.jsp
Generated servlet error:
rs cannot be resolved
这是我的程序:
<%@ page contentType= "text/html;charset=gb2312 " import= "java.sql.* " import= "java.lang.* " import= "java.util.* "%>
<%
request.setCharacterEncoding( "GBK ");
String lldept=request.getParameter( "ldept ");
String lltype=request.getParameter( "ltype ");
String llname=request.getParameter( "lname ");
String llnum=request.getParameter( "lnum ");
Int llmark=request.getParameter( "lmark ");
String submit=request.getParameter( "submit ");
if(submit.equals( "增加 "))
{
try{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver "); //注册驱动程序
Connection conn = DriverManager.getConnection( "jdbc:odbc:quincy ", "sa ", "sa ");
Statement stmt = conn.createStatement();
String sql = "insert into lesson(lname,lmark) values( ' "+llname+ " ', ' "+llmark+ " ') ";
ResultSet rs=stmt.executeQuery(sql);
if(rs==1){
out.print( " <td> " + rs.getString( "ldept ")+ " </td> ");
out.print( " <td> " + rs.getString( "ltype ")+ " </td> ");
out.print( " <td> " + rs.getString( "lname ")+ " </td> ");
out.print( " <td> " + rs.getString( "lnum ")+ " </td> ");
out.print( " <td> " + rs.getInt( "lmark ")+ " </td> ");
out.println( " <a href= 'manager1.html '> 返回登录页面 </a> ");
}else{}
rs.close();
stmt.close();
conn.close();
}
catch(SQLException ex)
{
out.println(ex.getMessage());
}
}
if(submit.equals( "删除 "))
{
try{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver "); //注册驱动程序
Connection conn = DriverManager.getConnection( "jdbc:odbc:quincy ", "sa ", "sa ");
Statement stmt = conn.createStatement();
int result=stmt.executeUpdate( "delete from lesson where lnum= ' "+llnum+ " ' ");
if(result==1){
out.println( "恭喜您,delete成功! <br> ");
out.println( " <a href= 'manager1.html '> 返回登录页面 </a> ");
}else{}
rs.close();
stmt.close();
conn.close();
}
catch(SQLException ex)
{
out.println(ex.getMessage());
}
}
if(submit.equals( "update "))
{
try{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver "); //注册驱动程序
Connection conn = DriverManager.getConnection( "jdbc:odbc:quincy ", "sa ", "sa ");
Statement stmt = conn.createStatement();
int result=stmt.executeUpdate( "update lesson set lname= ' "+llname+ " ' where lnum= ' "+llnum+ " ' ");
if(result==1){
out.println( "恭喜您,up成功! <br> ");
out.println( " <a href= 'manager1.html '> 返回登录页面 </a> ");
}else{}
rs.close();
stmt.close();
conn.close();
}
catch(SQLException ex)
{
out.println(ex.getMessage());
}
}
if(submit.equals( "query "))
{
try{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver "); //注册驱动程序
Connection conn = DriverManager.getConnection( "jdbc:odbc:quincy ", "sa ", "sa ");
Statement stmt = conn.createStatement();
ResultSet rs=stmt.executeQuery( "select * from lesson where lnum= ' "+llnum+ " ' ");
if (!rs.next())
{
out.println( " <center> ");
out.println( "no! ");
}
else{
while(rs.next())
{
String lnum = rs.getString( "lnum ");
String lname = rs.getString( "lname ");
}
}
out.println( " <a href= 'manager1.html '> 返回登录页面 </a> ");
rs.close();
stmt.close();
conn.close();
}
catch(SQLException ex)
{
out.println(ex.getMessage());
}
}
%>
[解决办法]
if(submit.equals( "增加 "))
.....
ResultSet rs=stmt.executeQuery(sql);
if(rs==1){
out.print( " <td> " + rs.getString( "ldept ")+ " </td> ");
=========================================
这里if(rs==1)明显是错误的 应该用if(rs.next())
[解决办法]
<%@ page contentType= "text/html;charset=gb2312 " import= "java.sql.* " import= "java.lang.* " import= "java.util.* "%>
这个也不对阿
import= "java.sql.*;java.lang*;java.util.* "
[解决办法]
楼上的真猛
[解决办法]
Int llmark = request.getParameter( "lmark ");
[解决办法]
An error occurred at line: 2 in the jsp file: /addke.jsp
Generated servlet error:
Int cannot be resolved or is not a type
Int llmark=request.getParameter( "lmark ");
是int,而且request.getParameter( "lmark ");得到的是string类型吧
还有
An error occurred at line: 2 in the jsp file: /addke.jsp
Generated servlet error:
rs cannot be resolved
int result=stmt.executeUpdate( "delete from lesson where lnum= ' "+llnum+ " ' ");
你定义的是result,用的却是rs
[解决办法]
什么都不用说了,开始改吧
[解决办法]
兄台又是一堆代码
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html