*
The moose likes Servlets and the fly likes Servlet [servlet-name] is currently unavailable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet [servlet-name] is currently unavailable" Watch "Servlet [servlet-name] is currently unavailable" New topic
Author

Servlet [servlet-name] is currently unavailable

Darren Hall
Greenhorn

Joined: Jan 22, 2006
Posts: 12
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

Joined: Jan 22, 2006
Posts: 12
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.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I'd like to confirm two things :
1. Is your class in a package ?
2. Is the class name correct ?


[My Blog]
All roads lead to JavaRanch
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
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

Joined: Jan 22, 2006
Posts: 12
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

Joined: Jan 22, 2006
Posts: 12
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

Joined: Jan 22, 2006
Posts: 12
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?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Darren Hall
Greenhorn

Joined: Jan 22, 2006
Posts: 12
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...)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60761
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet [servlet-name] is currently unavailable
 
Similar Threads
servlet not running but examples does
the requested resource is not available
Servlet not showing up in Browser
tomcat can't find index.jsp
invoke servlets from apache/htdocs/servlet