主题:jsp中调用javabean出错!!!
帮我者给30分
我在webapps目录下建了一个myjsp目录,
建立如下结构目录myjsp/WEB-INF/classes/access
首先我将编译的myaccess.class放到access目录下
然后在myjsp中放入了一个 index.jsp文件,调用access.myaccess类,但是在jbuilder
中说找不到该类,这是为什么,是不是跟WEB-INF下的web.xml文件有关啊?
jsp文件内容如下:
<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage=""%>
<%@page import="access.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body><%= request.getParameter("user")%>
<jsp:useBean id="view" scope="session" class="access.myaccess">
<form name="form1" method="post" action=""> 姓名
<input name="user" type="text" id="user">
密码
<input name="password" type="text" id="password">
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html>
web.xml文件如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Tomcat Documentation</display-name>
<description>
Tomcat Documentation.
</description>
<servlet>
<servlet-name>Sorry</servlet-name>
<servlet-class>access.myaccess</servlet-class>
</servlet>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
myaccess.java代码如下
package access;
import java.sql.*;
public class myaccess{
String sdbdriver="sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr="jdbc:odbc:studentdb";
Connection conn=null;
ResultSet rs =null;
public myaccess(){
try{
Class.forName(sdbdriver);
}
catch(java.lang.ClassNotFoundException e){
System.err.println("cuowu:" + e.getMessage());
}
}
public ResultSet executeQuery(String sql){
rs=null;
try {
conn=DriverManager.getConnection(sConnStr);
Statement stmt =conn.createStatement();
rs= stmt.executeQuery(sql);
}
catch(SQLException ex){
System.err.println("cuowu:" + ex.getMessage());
}
return rs;
}
public ResultSet executeUpdate(String sql){
rs=null;
try {
conn=DriverManager.getConnection(sConnStr);
Statement stmt =conn.createStatement();
rs= stmt.executeQuery(sql);
}
catch(SQLException ex){
System.err.println("cuowu:" + ex.getMessage());
}
return rs;
}
}
我在webapps目录下建了一个myjsp目录,
建立如下结构目录myjsp/WEB-INF/classes/access
首先我将编译的myaccess.class放到access目录下
然后在myjsp中放入了一个 index.jsp文件,调用access.myaccess类,但是在jbuilder
中说找不到该类,这是为什么,是不是跟WEB-INF下的web.xml文件有关啊?
jsp文件内容如下:
<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage=""%>
<%@page import="access.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body><%= request.getParameter("user")%>
<jsp:useBean id="view" scope="session" class="access.myaccess">
<form name="form1" method="post" action=""> 姓名
<input name="user" type="text" id="user">
密码
<input name="password" type="text" id="password">
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html>
web.xml文件如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Tomcat Documentation</display-name>
<description>
Tomcat Documentation.
</description>
<servlet>
<servlet-name>Sorry</servlet-name>
<servlet-class>access.myaccess</servlet-class>
</servlet>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
myaccess.java代码如下
package access;
import java.sql.*;
public class myaccess{
String sdbdriver="sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr="jdbc:odbc:studentdb";
Connection conn=null;
ResultSet rs =null;
public myaccess(){
try{
Class.forName(sdbdriver);
}
catch(java.lang.ClassNotFoundException e){
System.err.println("cuowu:" + e.getMessage());
}
}
public ResultSet executeQuery(String sql){
rs=null;
try {
conn=DriverManager.getConnection(sConnStr);
Statement stmt =conn.createStatement();
rs= stmt.executeQuery(sql);
}
catch(SQLException ex){
System.err.println("cuowu:" + ex.getMessage());
}
return rs;
}
public ResultSet executeUpdate(String sql){
rs=null;
try {
conn=DriverManager.getConnection(sConnStr);
Statement stmt =conn.createStatement();
rs= stmt.executeQuery(sql);
}
catch(SQLException ex){
System.err.println("cuowu:" + ex.getMessage());
}
return rs;
}
}