Fwd: Runtime Error While Executing Servlet Based Application
ratnam tatavarty <[email protected]> Fri, 24 Jun 2005 23:28:21 -0700 (PDT)
| Newsgroups | gmane.comp.java.ozone.user |
|---|---|
| Message-ID | <[email protected]> |
hello,
i have written a small servlet based application to maintain a hash-table of data. Its working fine as a console based application, but when i have modified it to servlet based on it is showing the error :
org.ozoneDB.OzoneInternalException: java.lang.ClassNotFoundException: ClassTableImpl .
please check out the source code files and kindly help me to sort out the problem.
Ratnam Tatavarty
JNTUCE, Hyderabad.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
ClassServlet.java
(text/java, 3.8 KB)
package web;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import java.util.*;
import org.ozoneDB.*;
import db.ClassTable;
import db.ClassTableImpl;
import web.*;
public class ClassServlet extends HttpServlet {
private ExternalDatabase db;
public ClassTable ct1;
public void init() throws ServletException {
try {
System.out.println("[ClassServlet] connecting to ozone...");
db = ExternalDatabase.openDatabase("ozonedb:remote://localhost:3333");
System.out.println("[ClassServlet] Connected!");
db.reloadClasses();
System.out.println("[ClassServlet] Classes reloaded");
}
catch (Exception e) {
e.printStackTrace();
}
}
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String message = "";
response.setContentType("text/html");
//get pw;
PrintWriter pw =response.getWriter();
//display;
try {
ClassTable ct = (ClassTable)(db.objectForName("ClassData"));
System.out.println("Object : " + ct);
if (ct==null) {
System.out.println("RATNAM");
System.out.println("Object 'Data' does not exist.");
ct = (ClassTable) db.createObject(ClassTableImpl.class.getName(), OzoneInterface.Public, "ClassData");
System.out.println("Creating object 'Data'....");
ct = (ClassTable)( db.objectForName("ClassData") );
}
if( request.getParameter("action").equals("create") ) {
System.out.println("Called For Object Create : ");
String ccode = request.getParameter("ccode");
String cname = request.getParameter("cname");
message += "<html> <head> </head> <body><p>Creating ClassTable object As </p><p><b> Abbreviation: '"+ ccode +"</b></p>'<p><b> Name : '"+ cname +"' </body> </html>";
System.out.println("[ClassServlet] Creating Object Instance :" + ccode );
ct.addClass_update(ccode, cname);
}//creating row
if( request.getParameter("action").equals("remove") ) {
String ccode = request.getParameter("ccode");
message += "<html> <head> </head> <body><p>Removing ClassTable object With <b> Abbreviation: '"+ ccode + "</b></p>";
System.out.println("[ClassServlet] Removing Object Instance :" + ccode );
String cname = ct.removeClass_update(ccode);
message += "<p><b> Name : '"+ cname + "</b></p></body> </html>";
System.out.print("Object Instance Value :" + cname +"\n" );
}//deleting row;
if( request.getParameter("action").equals("get") ) {
String ccode = request.getParameter("ccode");
message += "<html> <head> </head> <body><p>Retrieving ClassTable object With <b> Abbreviation: '"+ ccode +"</b></p>";
System.out.println("[ClassServlet] Retrieving Object Instance :" + ccode );
String cname = ct.getClass(ccode);
message += "<p><b> Name : '"+ cname +"</b></p></body> </html>";
System.out.print("Object Instance Value :" + cname +"\n" );
}//retrieving a row;
if( request.getParameter("action").equals("display") ) {
message += "<html><head> </head> <body><h2>Retrieving ClassTable Instances.</h2>";
System.out.print("[ClassServlet] Retrieving All Object Instances");
Hashtable table = ct.displayClass();
System.out.print("Object Instance Value :\n" + table +"\n" );
}//diplaying whole contents*/
} catch (Exception e) {
System.out.println("[HelloServlet] Can't connect to ozone." + e.toString());
e.printStackTrace();
message = "<html> <head> </head> <body> " + e.toString() + "</body> </html>";
}
PrintWriter out = response.getWriter();
System.out.println("[HelloServlet] Sending the following resonse back to client: " + message);
pw.println(message);
pw.flush();
pw.close();
}
}
ClassTable.java
(text/java, 345 B)
package db;
import org.ozoneDB.*;
import java.util.*;
public interface ClassTable extends OzoneRemote {
public void addClass_update(String ccode, String cname ) throws Exception;
public String removeClass_update(String ccode );
public String getClass( String ccode) throws Exception;
public Hashtable displayClass();
}
ClassTableImpl.java
(text/java, 1.1 KB)
package db;
import org.ozoneDB.*;
import java.util.*;
import db.ClassTable;
public class ClassTableImpl extends OzoneObject implements ClassTable {
/**
Set version of the serialized data to make it compatible with
new class versions.
*/
final static long serialVersionUID = 1L;
private Hashtable Classes;
public ClassTableImpl() {
System.out.println( getClass().getName() + "ctor..." );
Classes = new Hashtable();
}
public void addClass_update(String ccode, String cname) throws Exception {
Classes.put( ccode, cname );
}
public String removeClass_update( String ccode ) {
return (String)Classes.remove( ccode );
}
public String getClass( String ccode ) throws Exception {
return (String)Classes.get( ccode );
}
public Hashtable displayClass() {
Vector result = new Vector();
System.out.println("Checking Hashtables");
for (Enumeration e=Classes.elements(); e.hasMoreElements(); ) {
String st = (String)e.nextElement();
result.add( st );
}
System.out.println("Returning Hashtable");
return(Classes);
}
}
build.xml
(text/xml, 4.4 KB)
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="managerClass" default="deploy" basedir=".">
<property name="build.compiler" value="modern" />
<property name="build.dir" value="build/classes" />
<property name="web.dir" value="web" />
<property name="config.dir" value="conf" />
<property environment="env" />
<!-- needed by persistant objects -->
<property name="ozone.home" value="${env.OZONE_HOME}" />
<property name="lib.dir" value="${ozone.home}/lib" />
<!-- needed by OPP -->
<property name="java.home" value="${env.JAVA_HOME}" />
<property name="distribution.dir" value="dist" />
<property name="src.dir" value="src" />
<property name="java.doc.dir" value="${build.dir}/javadoc" />
<!-- need for servelt jar and to know the deployment dir -->
<property name="tomcat.home" value="${env.CATALINA_HOME}" />
<property name="deploy.dir" value="${tomcat.home}/webapps" />
<property name="web.inf" value="WEB-INF" />
<property name="war.file" value="${ant.project.name}.war" />
<path id="project.class.path" >
<!-- tools.jar is automatically included in class.path if JAVA_HOME is set -->
<pathelement path="${java.class.path}"/>
<pathelement path="${build.dir}" />
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${tomcat.home}/common/lib" includes="**/*.jar"/>
</path>
<target name="init">
<available file="${java.home}" type="dir" property="java.home.present"/>
<fail unless="java.home.present" message="Environment variable JAVA_HOME not set, cannot continue" />
<available file="${tomcat.home}" type="dir" property="tomcat.home.present"/>
<fail unless="tomcat.home.present" message="Environment variable TOMCAT_HOME not set, cannot continue" />
<available file="${ozone.home}" type="dir" property="ozone.home.present"/>
<fail unless="ozone.home.present" message="Environment variable OZONE_HOME not set, cannot continue" />
</target>
<target name="clean" >
<delete dir="${build.dir}" />
<delete dir="${distribution.dir}" />
</target>
<target name="prepare" depends="init">
<mkdir dir="${build.dir}" />
<mkdir dir="${distribution.dir}" />
</target>
<!--======================================================================
Compile all sources
=======================================================================-->
<target name="compile" depends="prepare">
<javac srcdir="${src.dir}"
destDir="${build.dir}"
classpathref="project.class.path"
failonerror="true" />
<!-- Builds the proxies -->
<java classname="org.ozoneDB.tools.OPP.OPP"
fork="yes"
failonerror="yes"
classpathref="project.class.path">
<arg line="-ks -st"/> <!-- keep the generated source, print stacktrace if error occurs -->
<arg line="-o${build.dir}"/>
<arg line="-s${src.dir}"/>
<arg line="db.ClassTableImpl"/>
</java>
</target>
<!--======================================================================
package it up
=======================================================================-->
<target name="package" depends="clean, prepare, compile">
<war warfile="${distribution.dir}/${war.file}"
webxml="${config.dir}/web.xml">
<!-- Web files: html, css and js files -->
<zipfileset dir="${web.dir}"
includes="**" />
<!-- Java classes -->
<zipfileset dir="${build.dir}"
includes="db/*.class, web/**"
prefix="${web.inf}/classes" />
<!-- Java jar files -->
<zipfileset dir="${lib.dir}"
includes="ozoneServer-*.jar"
prefix="${web.inf}/lib" />
</war>
</target>
<target name="tomcat.shutdown">
<!-- CATALINA_HOME is needed by the catalina script -->
<property name="CATALINA_HOME" value="${tomcat.home}" />
<exec dir="${tomcat.home}/bin" executable="${tomcat.home}/bin/catalina.bat" os="Windows 2000" >
<arg line="stop"/>
</exec>
<exec dir="${tomcat.home}/bin" executable="${tomcat.home}/bin/catalina.sh" os="Linux" >
<arg line="stop"/>
</exec>
</target>
<target name="deploy" depends="init, tomcat.shutdown, package" >
<delete dir="${deploy.dir}/${ant.project.name}" />
<unjar src="${distribution.dir}/${war.file}" dest="${deploy.dir}/${ant.project.name}" />
</target>
</project>
web.xml
(text/xml, 458 B)
<?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>
<servlet>
<servlet-name>ClassServlet</servlet-name>
<servlet-class>web.ClassServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ClassServlet</servlet-name>
<url-pattern>/ClassServlet</url-pattern>
</servlet-mapping>
</web-app>