• 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

Error 500- Internal servlet error

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Shiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic