求教JSP高手,The method delete(String) is undefined for the type conn

WhisperXb 2012-07-20 11:51:40
源码是这样的。
在usermanger.jsp用代码导入到delete.jsp中
<a href="delete.jsp?id=1">删除</a>

delete.jsp源码如下
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'wrong.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<jsp:useBean id="connDBBean2" scope="page" class="Conn.conn"/>
<%
String n = request.getParameter("id");
if(n.equals("1")){
String sql="delete from denglu where pkid=1";
connDBBean2.delete(sql);
response.sendRedirect("usermanger.jsp");

}
else if(n.equals("2")){
}
else{
}
%>


</body>
</html>

Conn.jsp源码如下
package Conn;
import java.sql.*;
public class conn{
String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr="jdbc:odbc:test";
Connection connect=null;
ResultSet rs=null;
public conn(){
try{
Class.forName(sDBDriver);
}catch(java.lang.ClassNotFoundException e)
{
System.err.println(e.getMessage());}
}
public ResultSet executeQuery(String sql){
//执行查询数据库操作的方法
try{
connect=DriverManager.getConnection(sConnStr);
//连接Access数据库
Statement stmt=connect.createStatement();
//创建向数据库提交查询语句的Statement对象
rs=stmt.executeQuery(sql);
//将查询结果保存再结果集rs中
}catch(SQLException ex){System.err.println(ex.getMessage());}return rs;
}
public String delete(String sql) {

PreparedStatement pre=null;
int num=0;
try {
connect=DriverManager.getConnection(sConnStr);
pre=connect.prepareStatement(sql);
num=pre.executeUpdate();
if(num>0){
return "1";
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "0";
}
}


tomcat显示的错误为:
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 31 in the jsp file: /delete.jsp
The method delete(String) is undefined for the type conn
28: String n = request.getParameter("id");
29: if(n.equals("1")){
30: String sql="delete from denglu where pkid=1";
31: connDBBean2.delete(sql);
32: response.sendRedirect("usermanger.jsp");
33:
34: }


conn.java中明明有delete方法啊,为什么行,求教。
...全文
777 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
蜗牛专注学习 2014-05-08
  • 打赏
  • 举报
回复
楼主解决问题了么?如果解决了可否给个解决方法~
xdezlqz 2012-08-19
  • 打赏
  • 举报
回复
我也遇到这个问题,在Java中是能操作数据库的。
可一到JSP中就这样了,到底是哪的问题?
虚心学习中……
toxcode 2012-08-11
  • 打赏
  • 举报
回复
解决了 吗?楼主
MiceRice 2012-07-20
  • 打赏
  • 举报
回复
需要检查下你的 conn 类,是否正确编译,而且正确发布到Web应用中了。

我见过几次是有人的类修改后根本没有正确发布到Web应用,结果白白浪费很多时间。
brightyq 2012-07-20
  • 打赏
  • 举报
回复
把jdk安装目录下的lib/tools.jar拷贝到tomcat安装目录下的common/lib目录下,然后重启tomcat,试试

另外看一下,编译和运行的jdk版本是否一致。
WhisperXb 2012-07-20
  • 打赏
  • 举报
回复
....姿势不对么。。
xhmlwaf 2012-07-20
  • 打赏
  • 举报
回复
<jsp:useBean id="connDBBean2" scope="page" class="Conn.conn"/>
你用的这个类貌似没有导入包 ,肯定通不过编译的。

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧