• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 810
  • Last Modified:

servlet mapping in web.xml in tomcat 5.5.7

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
kalyankondurie
Asked:
kalyankondurie
  • 2
1 Solution
 
arun99907Commented:
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
 
kalyankondurieAuthor Commented:
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
 
arun99907Commented:
>>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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now