?
Solved

servlet mapping in web.xml in tomcat 5.5.7

Posted on 2005-03-18
5
Medium Priority
?
796 Views
Last Modified: 2013-11-24
Hi all, I am new to Tomcat 5.5.7. I have a small web application which will have JSPs, HTMLs, Servlets.

I have created a directory structure in webapps for my application as Webapps /IMS(IMS is the name of my application)--here i put jsps and html files of my application -->/WEB-INF-- here i put web.xml and two folders -->/Classes-- here i put classes(servlets) for my application which will have some connection to mysql -->/lib--iput jar file for mysql connectivity

The issue now is when i tried to connect to server using http://localhost:8080/IMS, the default home page is appeared but after i tried to post the data from index.html to the servlet ValidateUser...it is throwing an error



type Exception report

message description The server encountered an internal error () that prevented it from fulfilling this request.

exception javax.servlet.ServletException: Wrapper cannot find servlet class ValidateUser or a class it depends on org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738) org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526) org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) java.lang.Thread.run(Thread.java:595)


root cause java.lang.ClassNotFoundException: ValidateUser org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1332) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1181) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738) org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526) org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) java.lang.Thread.run(Thread.java:595)

I have put the servlet mapping even in web.xml. Can any one help me out in this? I didnt change any of the other files on the server.

Thanks in Advance
Kalyan.
0
Comment
Question by:kalyankondurie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 3

Expert Comment

by:arun99907
ID: 13600102
Two ways:

1. One is using invoker servlet. Which maps to any general servlets.

Add the following as it is and rest all goes fine with all the servlets :

      <servlet>
        <servlet-name>invoker</servlet-name>
        <servlet-class>
          org.apache.catalina.servlets.InvokerServlet
        </servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
      </servlet>
      <servlet-mapping id="ServletMapping_1">
        <servlet-name>invoker</servlet-name>
        <url-pattern>/servlet/*</url-pattern>
      </servlet-mapping>  

here

http://localhost:8080/AppName/servlet/servlet1_name


2. Add servlet mapping for Each servlet.

      <servlet id="S4">
         <servlet-name>Servlet1</servlet-name>
         <servlet-class>servlet1_name</servlet-class>    /// ->> note if you are compiling servlets directly into classes folder.
       </servlet>                                                         /// remove these comments. If you are putting them in another  
                                                                              /// folder /classes/folder put it as folder.servlet1_name
      <servlet-mapping id="SM4">
         <servlet-name>servlet1</servlet-name>
         <url-pattern>/servlet/*</url-pattern>
      </servlet-mapping>

If you keep the mapping like this then call your servlet like this:

http://localhost:8080/AppName/servlet/servlet1_name



0
 

Author Comment

by:kalyankondurie
ID: 13608972
Hi,

Thanx for your reply. I tried with Invoker method first...but things are pretty same...
the second one..already I made a mapping but no result.....

I couldnot sort it out..it's giving the same error.........
even i tried with

<servlet>
      <servlet-name>ValidateUser</servlet-name>
      <servlet-class> org.apache.catalina.servlets.ValidateUser</servlet-class>
</servlet>

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

<welcome-file-list>
      <welcome-file>index.html</welcome-file>
</welcome-file-list>

in web.xml but no result....

further help is requested.. :-)

Kalyan.
0
 
LVL 3

Accepted Solution

by:
arun99907 earned 200 total points
ID: 13609024
>>root cause java.lang.ClassNotFoundException: ValidateUser org.apache.catalina.loader.WebappClassLoader.loadClass >>(WebappClassLoader.java:1332) org.apache.catalina.loader.WebappClassLoader.loadClass( >>WebappClassLoader.java:1181)

Error is very clear. ValidateUser class is not existing in org.apache.cataline.loader.WebappClassLoader.loadClass package.

Is ValidateUser the servletClass created by you?

<servlet>
     <servlet-name>ValidateUser</servlet-name>
     <servlet-class> org.apache.catalina.servlets.ValidateUser</servlet-class>
</servlet>

Where is ValidateUser class located?

According to your servlet tag, you are mentioning that you have a package structure like this:

Tomcat\Webapps\AppName\WEB-INF\classes\org\apache\catalina\servlets\ValidateUser.class

Are you sure that you are placing ValidateUser.class in the above hierarchy.

Incase you are keeping ValidateUser.class directly under Tomcat\Webapps\AppName\WEB-INF\classes\ValidateUser.class and giving the above mapping <servlet-class>org.apache.catalina.servlets.ValidateUser</servlet-class> it is an error.

If you are placing ValidateUser.class in \classes directory, then remove the mapping:

Remove entire:
============

<servlet>
     <servlet-name>ValidateUser</servlet-name>
     <servlet-class> org.apache.catalina.servlets.ValidateUser</servlet-class>
</servlet>

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

and Add just Invoker Servlet part:

Add
======
 <servlet>
        <servlet-name>invoker</servlet-name>
        <servlet-class>
          org.apache.catalina.servlets.InvokerServlet
        </servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
      </servlet>
      <servlet-mapping id="ServletMapping_1">
        <servlet-name>invoker</servlet-name>
        <url-pattern>/servlet/*</url-pattern>
      </servlet-mapping>  


Incase you mentioned a packaging line in ValidateUser.java (servlet) say package abc; You will have to place this in

\webapps\appname\WEB-INF\classes\abc\ValidateUser.java in such a case,

modify the existing Servlet mapping like this:

<servlet>
     <servlet-name>ValidateUser</servlet-name>
     <servlet-class>abc.ValidateUser</servlet-class>
</servlet>

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

Here <servlet-class> tag is very important.

IT SHOULD POINT TO THE CLASS FILE, STARTING FROM THE FOLDER INSIDE "\WEB-INF\classes"  directory till the class file name.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question