• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot Compile Class error on Tomcat 6.0

 
R Sharma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've written a small application consisting of an html page, a jsp page and a java class which I'l trying to deploy on tomcat 6.0 I'm getting the following error:
An error occurred at line: 13 in the jsp file: /update.jsp
update cannot be resolved to a type
10: String test_val=request.getParameter("test_val");
11: String v1=request.getParameter("v1");
12: String v2=request.getParameter("v2");
13: update obj=new update();
14: obj.setValues(test_id , test_val , v1 , v2);
15: obj.getId();
16: obj.getTestVal();


Heres the stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


Here's the code for the jsp:
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Updating the database</title>
</head>
<body>
<%@ page import="java.sql.*" %>
<%
String test_id=request.getParameter("test_id");
String test_val=request.getParameter("test_val");
String v1=request.getParameter("v1");
String v2=request.getParameter("v2");
update obj=new update();
obj.setValues(test_id , test_val , v1 , v2);
obj.getId();
obj.getTestVal();
obj.getVal1();
obj.getVal2();
int rows=obj.updateDB(test_id , test_val , v1 , v2);
%>
<p> Rows inserted in the database are: <%= rows %>. </p>
</body>
</html>


And here's the Java code:
import java.sql.*;
import java.lang.*;


public class update{
String emp_id , t_val , val1 , val2;
public void setValues(String test_id , String test_val , String v1 , String v2){
emp_id=test_id;
t_val=test_val;
val1=v1;
val2=v2;
}
public String getId(){
return emp_id;
}
public String getTestVal(){
return t_val;
}
public String getVal1(){
return val1;
}
public String getVal2(){
return val2;
}
public int updateDB(String emp_id , String test_val , String val1 , String val2)
throws SQLException , ClassNotFoundException
{
System.out.println("USAGE: update <id> <test_val> <val1> <val2>");
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc racle:thin:@//localhost:1521/XE";

Connection conn = DriverManager.getConnection(url , "username" , "password");
conn.setAutoCommit(true);
Statement smt = conn.createStatement();
int rows=smt.executeUpdate("INSERT INTO TEST(test_id , test_val , value1 , value2) VALUES('" + emp_id + "' , '" + test_val + "' , '" + val1 +
"' , '" + val2 + "')");
//System.out.println(rows + "rows inserted.");
return rows;
}
}

The HTML page and the JSP are placed under $install_dir/webapps/ROOT directory and the java file is under $install_dir/webapps/ROOT/WEB-INF/classes directory.
The TOMCAT_HOME, JAVA_HOME, classpath variables are all set in my environment. I just cant make out whats going wrong where.
Help is really appreciated!!!

Thanks!!

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

First, put the class 'update' in a package, for example 'com.mypackage' by adding this line to the source file:

package com.mypackage;

Then recompile and move the class file (update.class) to a subdirectory to match the package structure:

$install_dir/webapps/ROOT/WEB-INF/classes/com/mypackage

Second, import the class in your JSP file by adding a line like this:

<%@ page import="com.mypackage.update" %>
[ December 18, 2007: Message edited by: Jesper Young ]
 
R Sharma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your reply! I did exactly as you told, and now I'm getting the following error:

org.apache.jasper.JasperException: An exception occurred processing JSP page /update.jsp at line 20

17: obj.getTestVal();
18: obj.getVal1();
19: obj.getVal2();
20: int rows=obj.updateDB(test_id , test_val , v1 , v2);
21: %>
22: <p> Rows inserted in the database are: <%= rows %>. </p>
23: </body>

Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

javax.servlet.ServletException: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.update_jsp._jspService(update_jsp.java:87)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
java.lang.ClassLoader.loadClassInternal(Unknown Source)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
com.mypackage.update.updateDB(update.java:30)
org.apache.jsp.update_jsp._jspService(update_jsp.java:74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


The funny thing is that, the exact same code when deployed on oracle Jdeveloper works absolutely fine, doing the database insert correctly.
Some more help needed!!!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

Your code needs the Oracle JDBC driver, you should include the JAR file for that in the WEB-INF/lib directory of your web application, or put it in the lib directory of your Tomcat installation.
 
R Sharma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It Worked!!!


I'm HAPPIEEEEEE.....
Thanks a Ton!!!
I placed the jar files in the lib folder of Tomcat Installation dir and it works just fine.
Thanks a lottt again!!!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good to hear that the problem is solved.
[ December 19, 2007: Message edited by: Jesper Young ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic