aspose file tools*
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 Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Please Help, Thanks william,sainudheen, Bear .. " Watch "Please Help, Thanks william,sainudheen, Bear .. " New topic
Author

Please Help, Thanks william,sainudheen, Bear ..

G Gopal
Greenhorn

Joined: Sep 24, 2003
Posts: 4
Hello:
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 {
Class.forName(myDriver);
myConn = DriverManager.getConnection("jdbc racle:thin WHSE:1521 002","DM_DATA", "DM_DATA");
}
public abstract void cleanup() throws Exception;
public void takeDown() throws Exception {
cleanup();
myConn.close();
}
}
//
// 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() {
super();
}
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 {
stmt.close();
}
}

My jsp page is:
//
// dbqueryJB.jsp
// Put it in your JSP content directory
//
<html>
<head>
<title>
Oracle JDBC Bean & Tomcat JSP
</title>
</head>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="empbean" class="empQBean" scope="page" />
<body>
<h1>Employee Table</h1>
<table border="1" width="400">
<tr>
<td><b>File_Name</b></td>
<td><b>Load_FLG</b></td>
<td><b>Facility_NBR</b></td>
<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>
</tr>
<%
empbean.makeConnection();
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");
%>
<tr>
<td><%= empno %></td>
<td><%= ename %></td>
<td><%= job %></td>
<td><%= mgr %></td>
<td><%= hiredate %></td>
<td><%= sal %></td>
<td><%= comm %></td>
<td><%= deptno %></td>
</tr>
<%
}
}
empbean.takeDown();
%>
</table>
</body>
</html>

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"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<!--GENERATED_JSPS-->

<!-- JSPC servlet mappings start -->
<servlet>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<servlet-class>org.apache.jsp.index_jsp</servlet-class>

</servlet>






<servlet-mapping>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>
<!-- JSPC servlet mappings end -->
</web-app>
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.
GG
Sainudheen Mydeen
Ranch Hand

Joined: Aug 18, 2003
Posts: 218
Hi
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!
-------------------
Sainudheen
David O'Meara
Rancher

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.
thanks,
Dave.
G Gopal
Greenhorn

Joined: Sep 24, 2003
Posts: 4
Hello:
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;

I DO NOT HAVE TO CHANGE ANY THING IN web.xml CORRECT?
THANKS
gg
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
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.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please Help, Thanks william,sainudheen, Bear ..