Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > ServletException vs packages

Reply
Thread Tools

ServletException vs packages

 
 
googleRon
Guest
Posts: n/a
 
      02-25-2006
Gentle(wo)men,

I tried to invoke a simple servlet "Test1" which is (just for testing
purposes) part of the package "myPackage" and its class-file is in
C:\apache-tomcat-5.5.15\webapps\testApp\WEB-INF\classes\myPackage

I get from Tomcat the following error-report:

exception:
javax.servlet.ServletException: Error allocating a servlet instance

root cause:
java.lang.NoClassDefFoundError: Illegal name: myPackage/Test2

Here are some things that I did in advance to let the invocation of the
servlet works proper (as I presumed)

The first line in Test1.java is:
package myPackage;

I copied the class file Test1.class (which compiled well) from the
developing map to the map
C:\apache-tomcat-5.5.15\webapps\testApp\WEB-INF\classes\myPackage

I put the line
"C:\apache-tomcat-5.5.15\webapps\testApp\WEB-INF\classes" in the
environment variable ClassPath.

I adapted/edit web.xml bij adding the following lines:

<servlet>
<servlet-name>Test1</servlet-name>
<servlet-class>myPackage/Test2</servlet-class>
</servlet>

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

Still I get the error report I mentioned above.
Does someone know what causes the throw of this ServletException?

The interresting thing is that when I put the servlet (without the
package declaration!) in
the map "C:\apache-tomcat-5.5.15\webapps\testApp\WEB-INF\classes" it
works fine. No problem at all.
So I think it has something to do with the packages structure and the
environment settings.

Who can help me out please?

Thnx in advance

Ron

 
Reply With Quote
 
 
 
 
googleRon
Guest
Posts: n/a
 
      02-25-2006
At some lines in my message I mentioned by mistake Test2.
Some of you might think that this is the problem, but that isn't.
Where you read Test2 please replace it with Test1.
Sorry if I caused some confusion with mentioning Test2.

Greetings Ron

 
Reply With Quote
 
 
 
 
John C. Bollinger
Guest
Posts: n/a
 
      02-26-2006
googleRon wrote:
> I tried to invoke a simple servlet "Test1" which is (just for testing
> purposes) part of the package "myPackage" and its class-file is in
> C:\apache-tomcat-5.5.15\webapps\testApp\WEB-INF\classes\myPackage
>
> I get from Tomcat the following error-report:
>
> exception:
> javax.servlet.ServletException: Error allocating a servlet instance
>
> root cause:
> java.lang.NoClassDefFoundError: Illegal name: myPackage/Test2


Tomcat is right: "myPackage/Test2" is not a legal class name.

[...]

> The first line in Test1.java is:
> package myPackage;


[...]

> I adapted/edit web.xml bij adding the following lines:
>
> <servlet>
> <servlet-name>Test1</servlet-name>
> <servlet-class>myPackage/Test2</servlet-class>
> </servlet>


The class name should be "myPackage.Test2".

[...]

> The interresting thing is that when I put the servlet (without the
> package declaration!) in
> the map "C:\apache-tomcat-5.5.15\webapps\testApp\WEB-INF\classes" it
> works fine. No problem at all.


I don't believe that. Specifically, I don't believe that Tomcat will
ever load the servlet class if you tell it the name is
"myPackage/Test2", no matter where you put the corresponding class file.

--
John Bollinger

 
Reply With Quote
 
googleRon
Guest
Posts: n/a
 
      02-26-2006
Thnxalot John,
This was really helpfull.
A very stupid mistake of a rookie to put a / as separator in stead of a
..
In reply to your last remark I forgot to mention that when I put the
servlet in C:\...\classes I also changed the web.xml by deleting the
prefix "myPackage/", so the statement is
<servlet>
<servlet-name>Test1</servlet-name>
<servlet-class>Test1</servlet-class>
</servlet>

With regards,

Ron

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search Engine Optimization Packages India, SEO Packages Hyderabad,SEO Packages Firm visioninfosyslinks@gmail.com HTML 0 12-20-2007 08:45 AM
javax.servlet.ServletException: Cannot retrieve mapping for action suyogster@gmail.com Java 0 12-22-2005 11:46 AM
javax.servlet.ServletException: Wrapper cannot find servlet class HARI OM Java 0 05-04-2005 10:37 PM
javax.servlet.ServletException using Tomcat 5 Pia Java 0 09-11-2003 08:12 PM
translating SQLException to ServletException Mohun Biswas Java 0 07-25-2003 03:28 PM



Advertisments