This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Servlets and the fly likes Error 500- Internal servlet error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Error 500- Internal servlet error" Watch "Error 500- Internal servlet error" New topic
Author

Error 500- Internal servlet error

Soumendu Munshi
Greenhorn

Joined: Dec 15, 2001
Posts: 11
Hello,
I am a new servlet user trying to test with Servlet. I am using Apache 1.3 and Tomcat 3.2, conneting Tomcat and apache using Mod_jk on Win98.
Problem: I wrote a small Servlet (book eg) HelloWorld. It compiled well and I placed that at Tomcat_home/webapps/my-apps/
directory. So now when I try to execute the servlet using http://localhost:8080/my-apps/HelloWorld
it gives an error
Error: 500
Location: /my-apps/HelloWorld
Internal Servlet Error:
java.lang.NoClassDefFoundError: HelloWorld (wrong name: Helloworld)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
......... etc
Could anybody suggest what went wrong.
Thanks
Soum.
Craig Arthur
Greenhorn

Joined: Dec 14, 2001
Posts: 5
I had some fun with this yesterday.
1. Have you edited the "server.xml" file in the "conf" directory? You need an entry for your "my-apps" folder, something like:

2. Create a directory under my-apps called "WEB-INF". Create another directory in WEB-INF called "classes". Place your compiled servlet (and source) in the classes directory. Then, in your WEB-INF directory, you need a "web.xml" file. Here's an example:

Stop and start Tomcat, and you should be on your way!

[This message has been edited by greg millward (edited December 28, 2001).]
[This message has been edited by greg millward (edited December 28, 2001).]
[This message has been edited by greg millward (edited December 28, 2001).]
Soumendu Munshi
Greenhorn

Joined: Dec 15, 2001
Posts: 11
Hi Greg,
Thanks for your reply. I made changes to my Web.xml as-well-as Server.xml but of no use. Now the error message has change-
The page cannot be displayed.
Content of Web.xml file is-
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>

<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>

</web-app>
===============================================================
Extract of Server.xml
===============================================================
<Context path="/My-Apps"
docBase="My-Apps"
crossContext="false"
debug="0"
relodable="true"
privileged="true"/>
</Context>
===============================================================
My directory structure is
Tomcat
....(tomcat files)
|_webapps
|_My-Apps
|_META-INF
|_WEB-INF
|_web.xml
|_classes
|_HelloWorld.java
|_HelloWorld.class
Am I missing something. any more clue .
Thanks,
Soum
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
Hi - I think your web.xml file should be under:
\Tomcat\My-Apps\WEB-INF
and your class file(s) under:
\Tomcat\My-Apps\WEB-INF\classess
Your dir. structure doesn't look like that!
Additionally, you can go to:
\Tomcat\logs
and look at the latest log files for what happened when you started TC (i.e. did the app deploy or not).
HTH, Guy

Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Alternately, leave My-Apps where it is, and recognize that the 'docBase' attribute in web.xml is relative to TOMCAT_HOME.

ie, your server.xml entry should read:FYI: docBase can also contain absolute paths to anywhere on your system. So if you had a directory structure that was 'webapp' compliant (ie: it has WEB-INF,etc...) then you could make docBase say "C:\My Documents\myWebApp\FolderXYZ"
[This message has been edited by Mike Curwen (edited December 30, 2001).]
Soumendu Munshi
Greenhorn

Joined: Dec 15, 2001
Posts: 11
Thanks to Mike and Guy for your reply. My directory structure is exactly what Guy mentioned and my Server.xml is exactly what Mike mentioned. Since Server.xml too long I am only quoting what I have added to default Server.xml
<Context path="/My-Apps"
docBase="webapps/My-Apps"
crossContext="false"
debug="0"
relodable="true"
privileged="true" >
</Context>
Point worth noting is FORWARD SLASH after priviledged = "true" /> in Mikes example. Is this the way it should be?
Further I am getting error as
Error: 500
Location: /My-Apps/HelloWorld
Internal Servlet Error:
java.lang.NoClassDefFoundError: HelloWorld (wrong name: Helloworld)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
.....
I don't understand why it is not getting HelloWorld class file.
I would eagerly looking for feedback.
Thnaks,
Soum.
k swamy
Greenhorn

Joined: Jul 31, 2001
Posts: 14
Hi
Note what the error says...
"java.lang.NoClassDefFoundError: HelloWorld (wrong name: Helloworld)"
It couldnt find a class with "HelloWorld".
U'r class file would be Helloworld.class.
Not sure of this...anyway check it out.
Swamy
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16022
    
  20

Java is a CASE-SENSTIVE programming language :{. "HelloWorld" and "Helloworld" are considered to be 2 DIFFERENT classes!
ALso, remember that even in Windows, the case of the filenames matters. Although Windows will open a file named "Helloworld" if you ask for "HelloWorld", Java won't consider this to be the right file.


Customer surveys are for companies who didn't pay proper attention to begin with.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

S Munshi, the forward slash after privileged="true" just means I am closing the <context> tag in the same tag I open it in.

ie: <br/> or <p/> in plain HTML.

using <context attributelisthere /> or <context attributrelisthere> </context> are equally valid, but I did copy and past the code from Tomcat's server.xml, so this is how the Apache engineers wrote it.

And like kswamy and Tim said, watch that case sensitive Java!
Soumendu Munshi
Greenhorn

Joined: Dec 15, 2001
Posts: 11
Hello,
I checked everything thing- file name, class name including case but didn't get any clue as what is happening. I saw log file too but couldn't get anything out of it.
C:/tomcat/logs/servlet.log
001-12-30 10:43:22 - path="/examples" :jsp: init
2001-12-30 10:43:23 - path="/My-Apps" :jsp: init
2001-12-30 10:43:23 - path="/admin" :jsp: init
2001-12-30 10:43:23 - path="" :jsp: init
2001-12-30 10:43:23 - path="/test" :jsp: init
2001-12-30 10:43:23 - path="/tut-bookstore-tomcat.zip" :jsp: init
2001-12-30 10:43:23 - path="/bookstore" :jsp: init
2001-12-30 10:43:23 - path="/filesystem.attributes" :jsp: init
2001-12-30 10:43:23 - path="/HelloWorld.class" :jsp: init
To my guess it getting this from other place.
Thanks,
Soum.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

What is the name of the *source* file?

JDK1.3 under windows will let you compile a file named "helloworld.java" that contains a class called "HelloWorld".

Only when you try to run the class will you find the mistake:

Exception in thread "main" java.lang.NoClassDefFoundError: helloworld (wrong name: HelloWorld)

It's telling you the class it found is called "HelloWorld", but because of the class's file name, it is expecting "helloworld".

So make sure your source is exactly the same case as the class it is defining.
Soumendu Munshi
Greenhorn

Joined: Dec 15, 2001
Posts: 11
Finally I got it working. The problem was with n number of HelloWorld application I developed with Classpath pointing to them. So I changed Class name as asdf.class (an absurd name) and then tried- it worked.
One thing still not clear- do CLASSPATH has a vital role as I have CLASSPATH set to two working directory.
Thanks to all who responded.
Soum
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error 500- Internal servlet error