• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Servlet [servlet-name] is currently unavailable

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello.

I've seen topics similar to this one posted in this group, but I wasn't able to find a solution that worked for me, so I'l post my situation and hope someone here can help me.

I'm running Tomcat 5.0 and Apache 2 on Windows XP Pro. I'm using mod_jk to create the Apache-Tomcat connection.

I'm dealing with existing HTML and java servlets, and in our existing environment, all servlets were invoked using Tomcats invoker servlet. Moving forward, this will not be possible, however, in the short term, I want to get the existing site working using its current configuration but without using the invoker servlet. To start off, I've decided to try and get one servlet working properly, before I map all of the rest of them.

I successfully connected Tomcat and Apache together using mod_jk, and then mapped the example servlets as a test. After that success, I created a new directory under webapps called 'servlet', and added the following entry to my httpd.conf -

# Send servlet for context /servlet to 'flcworker'
<Location /servlet/*>
JkMount flcworker
</Location>

I then created a webapps/servlet/WEB-INF/web.xml file that looks like this -

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<servlet>
<servlet-name>FLCUpEvDisplayServlet</servlet-name>
<servlet-class>FLCUpEvDisplayServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FLCUpEvDisplayServlet</servlet-name>
<url-pattern>/FLCUpEvDisplayServlet</url-pattern>
</servlet-mapping>
</web-app>

Upon restarting Tomcat and Apache, I tried to point to the URL http://<localhost>/servlet/FLCUpEvDisplayServlet and received the following error -

exception
javax.servlet.ServletException: Wrapper cannot find servlet class FLCUpEvDisplayServlet or a class it depends on

root cause
java.lang.ClassNotFoundException: FLCUpEvDisplayServlet

In my log files I see the following (I'm not going to print the entire stack trace here, only what I think is relevant) -

2006-01-22 20:32:50 StandardContext[/servlet]Marking servlet FLCUpEvDisplayServlet as unavailable
2006-01-22 20:32:50 StandardContext[/servlet]Error loading WebappClassLoader
delegate: false
repositories:
/WEB-INF/classes/

2006-01-22 20:32:50 StandardWrapperValve[FLCUpEvDisplayServlet]: Allocate exception for servlet FLCUpEvDisplayServlet
javax.servlet.ServletException: Wrapper cannot find servlet class FLCUpEvDisplayServlet or a class it depends on

So, is this a simple classpath error? It looks like the classloader was unable to find my servlet, but since the class lives in the webapps/servlet/WEB-INF/classes directory, I thought it was included in the classpath of the app server by default, correct?

Can anyone explain what the cause of my problem is here?

Thanks.
[ January 22, 2006: Message edited by: Darren Hall ]
 
Darren Hall
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To make things simpler (potentially), I get the same exact log entries and behavior when I take Apache out of the mix and hit the servlet directly through Tomcat.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd like to confirm two things :
1. Is your class in a package ?
2. Is the class name correct ?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All classes used in servlets in any way should be in a package. Under some circumstances you can apparently get away without a package but you end up with hard to debug errors.
Bill
 
Darren Hall
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Satou -

> I'd like to confirm two things :
> 1. Is your class in a package ?

No. The person who originally programmed these servlets had something against packages (I guess). None of the java code running here specifies a package.

> 2. Is the class name correct ?

The class name is correct. In order to make sure of this (to avoid any typos I might have made), I actually copied and pasted it out of the windows explorer window and into my web.xml file.
 
Darren Hall
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
William -

> All classes used in servlets in any way should be in a package. Under some
> circumstances you can apparently get away without a package but you end up
> with hard to debug errors.
> Bill

I've heard this mentioned in many forums. Here's the deal - The person who originally wrote the code for this website made some (what I would consider) big mistakes. Not only did they not use packages in *any* of the java classes, but they also implemented 90% of the site as servlets. These servlets have an inheritance heirarchy (at most 3 levels deep), and only the base level servlets (of which there are 2 for some reason) interact with the few java classes (beans) the site uses (simple beans - not EJB). The few beans the application does use are not in packages, and have a smattering of behaviors - one stores query results, one is a standard 'app user' object, another is used to connect to the database and manage (and by 'manage' I mean open and close) that database connection, and the last one is read from text files.

The servlet that I'm trying to load instantialtes two other "base level" servlets, one of which instantiates the database connection manager (bean) and creates a database connection, and the other which instantiates a file reader (bean) and reads from a local config file (text file). All class files used by the application, whether servlet or bean, exist in the ${catalina.home}/webapps/servlet/WEB-INF/classes folder. There is no file structure at all under the classes directory - just all the class files in that one directory.

I'm not sure if any of this information is helpful, though, for solving the ClassDefNotFound issue (which appears to refer to the original servlet I was trying to load).
 
Darren Hall
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've also heard that the current Servlet Spec does require that servlet classes be in a package. Is this correct, and could this be causing my issues?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The requirement is in the JRE:
Starting with Java 1.4, classes in the default package (no declared package) can not be imported from classes in declared packages.
 
Darren Hall
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, I have done more with this issue...

I added the "HelloWorldExample" servlet to my webapps/servlet/WEB-INF/classes folder and I modified the web.xml for that application to include a servlet mapping for the HelloWorldExample servlet as such -

<servlet>
<servlet-name>HelloWorldExample</servlet-name>
<servlet-class>HelloWorldExample</servlet-class>
</servlet>

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

Upon reloading tomcat and pointing my borwser to "http://<localhost>/servlet/HelloWorldExample" I got an error telling me the ResourceBundles could not be located.

(For anyone who does not have the servlet example that come with Tomcat, the 'HelloWorldExample' servlet uses a resource bundle so that the output strings it writes are based on the curent locale. Here is the code -

...
ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());

response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println("<html>");
out.println("<head>");

String title = rb.getString("helloworld.title");

out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
...

I commented out the ResourceBundle line and made the reference to the variable 'title' static text, and the servlet ran fine.

So, this tells me I *can* run a servlet with no package specified and map it through my web.xml file - however, the code only executed after the ResourceBundle code was removed.

Now the code runs properly in its default /servlets-examples context fine, even with the ResourceBundle in place, and only failed when I moved it to my /servlet context. Does this tell me its a classpath issue, or...?

(I'm getting confused...)
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You current configuration is fragile and prone to problems. Your best bet is to buck up and refactor classes and resources to non-default packages and eliminate that as a potential source of problems. Then if problems ensue, it should be much more straight-forward to try and track them down.
 
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic