learn java
The moose likes JSP and the fly likes Please Help, Thanks william,sainudheen, Bear .. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Please Help, Thanks william,sainudheen, Bear .. " Watch "Please Help, Thanks william,sainudheen, Bear .. " New topic

Please Help, Thanks william,sainudheen, Bear ..

G Gopal

Joined: Sep 24, 2003
Posts: 4
Thanks Sainudheen, made the changes in my JSP page as you pointed out and it works. Thanks to Willam and Bear for the advise too. O.K This is what I did based on your advice. Now I get a different error. I am using Tomacat 5.0 under W2K OS.
I created 2 classes here it is:
// sqlBean.java
// Compile this and put it in your 'WEB-INF\classes' directory
import java.sql.*;
import java.io.*;
public abstract class sqlBean{
private String myDriver = "oracle.jdbc.driver.OracleDriver";
private String myURL = "jdbc racle:thin m_datamart/dm_datamart@P002:1521 002";

protected Connection myConn;
public void makeConnection() throws Exception {
myConn = DriverManager.getConnection("jdbc racle:thin WHSE:1521 002","DM_DATA", "DM_DATA");
public abstract void cleanup() throws Exception;
public void takeDown() throws Exception {
// empQBean.java
// Compile this and put it in your 'WEB-INF\classes' directory
import java.sql.*;
import java.io.*;

public class empQBean extends sqlBean {
String myEmpSQL = "select * from load_status";
ResultSet myResultSet = null;
Statement stmt = null;
public empQBean() {
public boolean getNextEmployee() throws Exception {
return myResultSet.next();
public String getColumn(String inCol) throws Exception {
return myResultSet.getString(inCol);
public boolean getEmployees() throws Exception {
String myQuery = myEmpSQL;
stmt = myConn.createStatement();
myResultSet = stmt.executeQuery(myQuery);
return (myResultSet != null);
public void cleanup() throws Exception {

My jsp page is:
// dbqueryJB.jsp
// Put it in your JSP content directory
Oracle JDBC Bean & Tomcat JSP
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="empbean" class="empQBean" scope="page" />
<h1>Employee Table</h1>
<table border="1" width="400">
<td><b>Load Status</b></td>
<td><b>Migragte Flag</b></td>
<td><b>Load ID</b></td>
<td><b>History Start</b></td>
<td><b>History End</b></td>
if (empbean.getEmployees() ){
while (empbean.getNextEmployee() ){
String empno = empbean.getColumn("FILE_NAME");
String ename = empbean.getColumn("LOAD_FLG");
String job = empbean.getColumn("FACILITY_NBR");
String mgr = empbean.getColumn("LOAD_STATUS_TIMESTAMP");
String hiredate = empbean.getColumn("MIGRATE_HISTORY_FLG");
String sal = empbean.getColumn("LOAD_ID");
String comm = empbean.getColumn("HISTORY_LOAD_START_TIMESTAMP");
String deptno = empbean.getColumn("HISTORY_LOAD_END_TIMESTAMP");
<td><%= empno %></td>
<td><%= ename %></td>
<td><%= job %></td>
<td><%= mgr %></td>
<td><%= hiredate %></td>
<td><%= sal %></td>
<td><%= comm %></td>
<td><%= deptno %></td>

I copied both the class files into c:\tomcat 5.0\webapps\ROOT\WEB-INF\classes\org\apache\jsp\ folder. I have my JSP page in c:\tomcat 5.0\webapps\ROOT\. I did not make any changes to WEB.xml in WEB-INF folder. SHOULD I MAKE A CHANGE. IF SO WHAT SHOULD IT LOOK LIKE? I already have something like this in web.xml file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
<display-name>Welcome to Tomcat</display-name>
Welcome to Tomcat

<!-- JSPC servlet mappings start -->


<!-- JSPC servlet mappings end -->
When i point my browser address to the jsp i get the following error:
java.lang.NoClassDefFoundError: org/apache/jsp/empQBean (wrong name: empQBean)
Please Help. I am new to Java, JSP stuff and TOMCAT also.
Thanks for your help in advance.
Sainudheen Mydeen
Ranch Hand

Joined: Aug 18, 2003
Posts: 218
Since you don't have a package declaration in your files, put your class files in c:\tomcat 5.0\webapps\ROOT\WEB-INF\classes folder directly.
Try it out!
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Please don't post large sections of irrelevant code. Try to keep it to specific sections, and always use the UBB [code] tag.
I think Sainudheen is right though. You haven't packaged your code, so it belongs on the web server classpath, which includes in classes directory. Therefore your class your go in this directory and not a subdirectory.
G Gopal

Joined: Sep 24, 2003
Posts: 4
I tried putting the class in webapps\root\classes folder. I get the following error now:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 13 in the jsp file: /dbqueryJB.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\dbqueryJB_jsp.java:48: cannot resolve symbol
symbol : class empQBean
location: class org.apache.jsp.dbqueryJB_jsp
empQBean empQBean = null;

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12913
Instead of:

You must have your bean class in a package, specify the package in the useBean tag specify the package in an "import" and put the compiled bean class under WEB-INF/classes/yourpackage/ directory.

I know - sometimes you can get things to work without a package but it just is not worth the confusion. Always put servlet/jsp related classes in packages.
I agree. Here's the link: http://aspose.com/file-tools
subject: Please Help, Thanks william,sainudheen, Bear ..