Just got this book today and I typed in the Project1 example. After I
fixed the errors by looking at the book's site and reviewing the
errata, I still have an error. Has anyone else had issues typing in
the examples in the book?
For those of you who aren't familar with the book, here is the Java
program they ask to type in and compile
--------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Ch1Servlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException {
PrintWriter out = response.getWriter();
java.util.Date today = new java.util.Date();
out.println("<html> " +
"<body>" +
"<h1 align=center>HF\'s Chapter1 Servlet</h1>"
+ "<br>" + today + "</body>" + "</html>");
}
}
--------------
and here is the web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
Version="2.4">
<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Chapter1 Servlet</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>
</web-app>
> Just got this book today and I typed in the Project1 example. After I
> fixed the errors by looking at the book's site and reviewing the
[quoted text clipped - 40 lines]
> </servlet-mapping>
> </web-app>
What is the error you are getting?

Signature
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
jctown@nb.sympatico.ca - 28 Jul 2006 11:01 GMT
----snip----
> What is the error you are getting?
>
[quoted text clipped - 6 lines]
> 'If there is one, Knowledge is the "Fountain of Youth"'
> -William E. Taylor, Regular Guy (1952-)
-------------------------------------HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented
it from fulfilling this request.
exception
javax.servlet.ServletException: Error allocating a servlet instance
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.UnsupportedClassVersionError: Bad version number in .class
file
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1812)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:866)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1319)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1198)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Unknown Source)
note The full stack trace of the root cause is available in the Apache
Tomcat/5.5.17 logs.
Apache Tomcat/5.5.17
Mark Space - 29 Jul 2006 06:23 GMT
> root cause
>
> java.lang.UnsupportedClassVersionError: Bad version number in .class
> file
Weird, never seen this. It looks like you compiled against one version
of the Java compiler, but Tomcat is using another. Or some kind problem
mixing different versions of library files in Tomcat.
What version of Tomcat do you have? Can you make it show it's default
configuration type stuff? Will it serve basic files (not JSP)?
What version of the JDK are you using? Any other tools involved
(NetBeans, Eclipse)?
jctown@nb.sympatico.ca - 29 Jul 2006 14:40 GMT
> > root cause
> >
[quoted text clipped - 10 lines]
> What version of the JDK are you using? Any other tools involved
> (NetBeans, Eclipse)?
Tomcat 5.5
I have other JSP's that work fine with it
But I think I just found something...
Tomcat Version JVM Version JVM Vendor OS Name OS Version OS
Architecture
Apache Tomcat/5.5.17 1.5.0_06-b05 Sun Microsystems Inc. Windows XP 5.1
x86
Tomcat is using a different JVM version than I am compiling
under...could this be the problem, and if so, how would I make Tomcat
use 1.6 ?
java version "1.6.0-rc"
Java(TM) SE Runtime Environment (build 1.6.0-rc-b90)
Java HotSpot(TM) Client VM (build 1.6.0-rc-b90, mixed mode, sharing)
No IDE ...they say in the book not to use one so I didn't, although I
would normally use Eclipe
jctown@nb.sympatico.ca - 29 Jul 2006 15:14 GMT
> > root cause
> >
[quoted text clipped - 10 lines]
> What version of the JDK are you using? Any other tools involved
> (NetBeans, Eclipse)?
Mark, I fixed it. I uninstalled the jdk6 instance, made sure my
JAVA_HOME was set properly, PATH includes %JAVA_HOME%/bin and then
recompiled... once I recompiled the class it worked fine. I would like
to know, however, how to make it work with JDK1.6 because that is the
next version....
"jctown@nb.sympatico.ca" <jctown@nb.sympatico.ca> said:
>Just got this book today and I typed in the Project1 example. After I
>fixed the errors by looking at the book's site and reviewing the
>errata, I still have an error. Has anyone else had issues typing in
>the examples in the book?
As you found out, the issue was not with Tomcat, but trying to run your
compiled software with a Java version earlier than that used to compile
your software.
As for that -- you should be able to change your Tomcat installation
to use a JDK of your choice - so it should be possible to run your
Tomcat with Java 1.6. As for details on choosing the Tomcat JRE version
on Windows, I don't know (could be just changing the PATH nad JAVA_HOME).
However, looks like the book has another gotcha waiting for you:
>For those of you who aren't familar with the book, here is the Java
>program they ask to type in and compile
[quoted text clipped - 4 lines]
>
>public class Ch1Servlet extends HttpServlet {
...
>}
This class belongs to an "unnamed package" (i.e. there is no "package"
statement in the source file). This is frowned upon, and not guaranteed
to work.
So, what is needed is to add a line containing:
package somePackage;
to the start of your Java files - but doing this causes a small avalanche
of other changes:
- servlet class names in web.xml must be fully qualified, i.e.
somePackage.Ch1Servlet instead of plain Ch1Servlet
- you must either use "import somePackage.*;" in your code referring to
other classes you create, or again use fully qualified names in the
code
- the compiled class files must be placed in subdirectory named somePackage
Still, I'd recommend to go through this trouble from the beginning, to
avoid being bitten later on.

Signature
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)