• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Errors Running JSP Page

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am getting the error below when I run a JSP ap to add books to an inventory:
Thanks again to all.
ddave
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: -1 in the jsp file: null
Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] C:\jakarta-tomcat-4.1.24\work\Standalone\localhost\begjsp-ch16\booklist_jsp.java:10: package com.wrox.databases does not exist
[javac] import com.wrox.databases.*;
[javac] ^
[javac] C:\jakarta-tomcat-4.1.24\work\Standalone\localhost\begjsp-ch16\booklist_jsp.java:46: package com.wrox.databases does not exist
[javac] com.wrox.databases.Books book = null;
[javac] ^
[javac] C:\jakarta-tomcat-4.1.24\work\Standalone\localhost\begjsp-ch16\booklist_jsp.java:48: package com.wrox.databases does not exist
[javac] book = (com.wrox.databases.Books) pageContext.getAttribute("book", PageContext.PAGE_SCOPE);
[javac] ^
[javac] C:\jakarta-tomcat-4.1.24\work\Standalone\localhost\begjsp-ch16\booklist_jsp.java:51: package com.wrox.databases does not exist
[javac] book = (com.wrox.databases.Books) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "com.wrox.databases.Books");
[javac] ^
[javac] 4 errors
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:353)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:370)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:473)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:190)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:536)
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Do you have the package com.wrox.databases in the classpath?? Just check if you have put the classes from com.wrox.databases package in the "lib" folder of your application folder.
webapps
|
---yourApp
|
----WEB-INF
|
----lib
|
---com
|
---wrox etc...

Hope this helps you,
Uma.
 
Dolfandave Uyemura
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Uma,
"Do you have the package com.wrox.databases in the classpath?? Just check if you have put the classes from com.wrox.databases package in the "lib" folder of your application folder."
I don't believe I have done this. How do you do this? Is it after I compile the Java application? It sounds like I need to copy the classes and NOT an issue w/ my Autoexec.bat file? Please confirm and thank you.
ddave
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
The classpath issue you're having seems to reside with the servlet container. While the .wrox packages may be in your system classpath (allowing you to compile the relevant class files and deploy your app), the servlet container itself has its own classpath, which it uses when compiling JSP's. As a result, you should add any necessary .jar files to your application's WEB-INF/lib directory. Any jar files in this directory are automatically added to the servlet container's classpath on application startup. The .jar file you're missing is the one that contains the "com.wrox.databases" classes. As an alternative to a jar file you can also mirror the package structure in WEB-INF/lib and add the actual class files. Deploying as a .jar file however, is easier and the servlet container "unjars" the contents of the .jar file into its requisite directories (and the class file in those directories). Hope this helps!
--BW
 
Dolfandave Uyemura
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I continue to get the same error. This is getting frustrating. I compiled and ran a few scripts that interact with a MySQL database per Beginning JSP Web Development by Wrox Press. I have no problem interacting with the database but when I try to go to the localhost site (http://localhost:8080/begjsp-ch16/booklist.jsp), I get the errors I initially posted. The booklist.jsp file looks like this:
<%@ page language="java"
import="java.sql.*, java.io.*, java.util.*, com.wrox.databases.*"
errorPage="error.jsp" %>
<jsp:useBean id="book" class="com.wrox.databases.Books" />
<html>
<head>
<title> Wrox Press Ltd. </title>
</head>
<body>
<h1> Wrox Press Ltd.</h1>
<h2> List of Books </h2>
<a href="newbook.jsp"><b>Add More Books</b></a>
<form action="delete.jsp" method="post">
<table border="1">
<tr>
<td><b>ID:</b></td>
<td><B>Title:</b></td>
<td><B>Price:</b></td>
</tr>
<%
book.connect();
ResultSet rs = book.viewBooks();
while (rs.next()) {
%>
<tr>
<td>
<input type="checkbox" name="pkey"
value="<%= rs.getString("Title_ID") %>" />
</td>
<td><%= rs.getString("Title") %></td>
<td><%= rs.getString("Price") %></td>
</tr>
<%
}
%>
</table><br />
Check books for deletion.<BR>
<input type="submit" value="Delete All Checked Books">
</form>
<% book.disconnect(); %>
</body>
</html>
===================================
and is in this file: c:\jakarta-tomcat-4.1.24\webapps\begjsp-ch16
The Books.java application is in c:\jakarta-tomcat-4.1.24\webapps\begjsp-ch16\web-inf\classes\com\wrox\databases per very specific instructions from the text.
Books.java is as follows:
package com.wrox.databases;
import java.sql.*;
import java.util.*;
public class Books {
String error;
Connection con;
public Books() { }
public void connect() throws ClassNotFoundException,
SQLException,
Exception {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(
"jdbc:mysql://localhost/Wrox ?user=root&password=");
} catch (ClassNotFoundException cnfe) {
error = "ClassNotFoundException: Could not locate DB driver.";
throw new ClassNotFoundException(error);
} catch (SQLException cnfe) {
error = "SQLException: Could not connect to database.";
throw new SQLException(error);
} catch (Exception e) {
error = "Exception: An unknown error occurred while connecting " +
"to database.";
throw new Exception(error);
}
}
public void disconnect() throws SQLException {
try {
if ( con != null ) {
con.close();
}
} catch (SQLException sqle) {
error = ("SQLException: Unable to close the database connection.");
throw new SQLException(error);
}
}
public ResultSet viewBooks() throws SQLException, Exception {
ResultSet rs = null;
try {
String queryString = ("SELECT * FROM Book;");
Statement stmt = con.createStatement();
rs = stmt.executeQuery(queryString);
} catch (SQLException sqle) {
error = "SQLException: Could not execute the query.";
throw new SQLException(error);
} catch (Exception e) {
error = "An exception occured while retrieving books.";
throw new Exception(error);
}
return rs;
}
public void addBooks(int id, String title, float price, int cid)
throws SQLException, Exception {
if (con != null) {
try {
PreparedStatement updatebooks;
updatebooks = con.prepareStatement(
"insert into Book values(?, ?, ?, ?);");
updatebooks.setInt(1, id);
updatebooks.setString(2, title);
updatebooks.setInt(3, cid);
updatebooks.setFloat(4, price);
updatebooks.execute();
} catch (SQLException sqle) {
error = "SQLException: update failed, possible duplicate entry";
throw new SQLException(error);
}
} else {
error = "Exception: Connection to database was lost.";
throw new Exception(error);
}
}
public void removeBooks(String [] pkeys) throws SQLException, Exception {
if (con != null) {
try {
PreparedStatement delete;
delete = con.prepareStatement("DELETE FROM Book WHERE Title_ID=?;");
for (int i = 0; i < pkeys.length; i++) {
delete.setInt(1, Integer.parseInt(pkeys[i]));
delete.execute();
}
} catch (SQLException sqle) {
error = "SQLException: update failed, possible duplicate entry";
throw new SQLException(error);
} catch (Exception e) {
error = "An exception occured while deleting books.";
throw new Exception(error);
}
} else {
error = "Exception: Connection to database was lost.";
throw new Exception(error);
}
}
}
==============================
Thanks again,
ddave
 
Dolfandave Uyemura
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also,
I forgot to mention that I copied the Book.class file after I compiled Book.java into the lib file adjacent to the path ....com\wrox\database\Book.java FWIW.
ddave
 
Dolfandave Uyemura
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"The classpath issue you're having seems to reside with the servlet container. While the .wrox packages may be in your system classpath (allowing you to compile the relevant class files and deploy your app), the servlet container itself has its own classpath, which it uses when compiling JSP's. As a result, you should add any necessary .jar files to your application's WEB-INF/lib directory. Any jar files in this directory are automatically added to the servlet container's classpath on application startup. The .jar file you're missing is the one that contains the "com.wrox.databases" classes"
So Brian,
Where do you get these .jar files?
ddave
reply
    Bookmark Topic Watch Topic
  • New Topic