Calling javaBean from JSP
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Soloist_He
Posted On:   Saturday, October 6, 2007 10:42 AM

here is JSP code: <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %> <% ResultSet rs = dataconn.executeQuery("SELECT * FROM grade"); while(rs.next()) { out.println(rs.getString("name")); out.println(rs.getString("id")); } %> Here is Errors: org.apache.jasper.JasperException: Exception in JSP: /mydata.jsp:10 javax.servlet.ServletException: Unresolved compilation problem: The public type dbconn must be defined in its own file 7: 8: 9: 10:    More>>
here is JSP code:
			
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>



<%
ResultSet rs = dataconn.executeQuery("SELECT * FROM grade");
while(rs.next())
{
out.println(rs.getString("name"));
out.println(rs.getString("id"));
}
%>




Here is Errors:




			
org.apache.jasper.JasperException: Exception in JSP: /mydata.jsp:10
javax.servlet.ServletException: Unresolved compilation problem:
The public type dbconn must be defined in its own file

7:
8:
9:
10:
11: <%
12: ResultSet rs = dataconn.executeQuery("SELECT * FROM grade");
13: while(rs.next())





here is JavaBean code block:

			
package mydata;
import java.sql.*;
public class dbconn
{
String sdbdriver="sun.jdbc.odbc.JdbcOdbcDriver";
String sconnstr="jdbc:odbc:JavaDataTest";
Connection conn=null;
ResultSet rs=null;
public dbconn()
{
try{
Class.forName(sdbdriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println(e.getMessage());

}
}
public ResultSet executeQuery(String squery)
{
try{
conn=DriverManager.getConnection(sconnstr);
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(squery);
}
catch(SQLException e)
{
System.err.println(e.getMessage());

}
return rs;
}
public int executeUpdate(String squery)
{
int result=0;
try{

conn=DriverManager.getConnection(sconnstr);
Statement stmt=conn.createStatement();
result=stmt.executeUpdate(squery);
}
catch(SQLException e)
{
System.err.println(e.getMessage());
}
return result;
}

}







My god!

Have spent me for more than 1 hours can not also find mistake .
Who can tell me where mistake ¬£¬¨thanks!    <<Less

Re: Calling javaBean from JSP

Posted By:   Christopher_Koenigsberg  
Posted On:   Wednesday, October 10, 2007 08:14 PM

Well, first, do you have a "WEB-INF/classes/mydata/dbconn.class" in your .war file, which was compiled from "dbconn.java" containing your given source code for that class? (or equivalently, a .jar file in the WEB-INF/lib dir of your .war file, where the content of the .jar file has a "mydata/dbconn.class")


If you do, then, second, hmm.... JavaBean stuff uses certain conventions about names...... I wonder, could it be that it doesn't like your using all lowercase for the class name? what if you were to rename "dbconn" to "Dbconn" and try that? ("Dbconn.java", "public class Dbconn", useBean 'class="mydata.dbconn"')

About | Sitemap | Contact