how to cofigure and run servlet in tomcat 6.0.18

hi all,
I got this system installed
linux centos 5.0

[root@localhost ~]# java -version
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)

tomcat : 6.0.18 on linux

when runing the startup.sh I get the following messages
[root@localhost ~]# '/home/hatem/Desktop/startup.sh'
Using CATALINA_BASE:   /hatem/install/jsp_servlet/tomcat/apache-tomcat-6.0.18/
Using CATALINA_HOME:   /hatem/install/jsp_servlet/tomcat/apache-tomcat-6.0.18/
Using CATALINA_TMPDIR: /hatem/install/jsp_servlet/tomcat/apache-tomcat-6.0.18//temp
Using JRE_HOME:       /usr/share/java/jre/


I got those environment server variables set in tomcat startup.sh file and shutdown.sh before any code run

export PATH="/usr/share/java/bin/":$PATH;

export JAVA_HOME="/usr/share/java/";

export JRE_HOME="/usr/share/java/jre/";

export CATALINA_HOME="/hatem/install/jsp_servlet/tomcat/apache-tomcat-6.0.18/";

export CLASSPATH=.:"/hatem/install/jsp_servlet/tomcat/apache-tomcat-6.0.18/lib/servlet-api.jar":$CLASSPATH


my questions is :
1. how to run my servlet and  deploy it on that system using deployment descriptor and what is the file system structure I have to create myself if not exist
2. how to run the invoker servlet so that I can run my servlet without dployment descriptor effort
3. where to put the <context ..... /> in the configuration files

attached the files under conf directory in tomcat installation
server.conf.zip
hatem_from_mesrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gibu GeorgeChief Technology OfficerCommented:
You don't need to modify the any of the configuration for deploying a servlet. Create a new folder in the webapps folder say testWebApp. The folder name will be your application context. Then crea folder WEB-INF inside that create classes folder inside the WEB-INF where you need to place your servlet class. In the WEB-INF create a file web.xml which contains the servlet mapping. The structure of web.xml is like that in the code snippet. After this you can access the servlet using http://:/testWebApp/TestServlet
<?xml version="1.0"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <display-name>testWebApp</display-name>
 <servlet>
  <servlet-name>TestServlet</servlet-name>
  <servlet-class>test.TestServlet</servlet-class>
 </servlet>
 <servlet-mapping>
  <servlet-name>TestServlet</servlet-name>
  <url-pattern>/TestServlet</url-pattern>
 </servlet-mapping>
</web-app>

Open in new window

0
hatem_from_mesrAuthor Commented:
would you please send me the test servlet java file to compile it
0
hatem_from_mesrAuthor Commented:
sorry,
here is my code


package examples;
 
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
 
public class HelloWorldServlet extends HttpServlet
{
    public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
        throws IOException
    {
// Tell the Web server that the response is HTML.
        response.setContentType("text/html");
 
// Get the PrintWriter for writing out the response.
        PrintWriter out = response.getWriter();
 
// Write the HTML back to the browser.
        out.println("<html>");
        out.println("<body>");
        out.println("<h1>Hello World!</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}

Open in new window

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

hatem_from_mesrAuthor Commented:
when i browse
http://localhost:8080/testWebApp/examples.HelloWorldServlet
i get
HTTP Status 404 - /testWebApp/examples.HelloWorldServlet

type Status report

message /testWebApp/examples.HelloWorldServlet

description The requested resource (/testWebApp/examples.HelloWorldServlet) is not available.
Apache Tomcat/6.0.18
any help
0
hatem_from_mesrAuthor Commented:
also here is my changes to web.xml
<?xml version="1.0"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <display-name>testWebApp</display-name>
 <servlet>
  <servlet-name>HelloWorldServlet</servlet-name>
  <servlet-class>examples.HelloWorldServlet</servlet-class>
 </servlet>
 <servlet-mapping>
  <servlet-name>HelloWorldServlet</servlet-name>
  <url-pattern>/examples.HelloWorldServlet</url-pattern>
 </servlet-mapping>
</web-app>

Open in new window

0
hatem_from_mesrAuthor Commented:
attached this for clarifications
[root@localhost testWebApp]# tree
.
`-- WEB-INF
    |-- classes
    |   |-- HelloWorldServlet.java
    |   `-- examples
    |       `-- HelloWorldServlet.class
    `-- web.xml

3 directories, 3 files
[root@localhost testWebApp]#

0
Gibu GeorgeChief Technology OfficerCommented:
where is your WEB-INF folder?
0
hatem_from_mesrAuthor Commented:
it's in the tree result man first one
0
hatem_from_mesrAuthor Commented:
- I copied the examples directory to install folder/lib and it worked since there is no classes folder
- I changed  the printed message and recompiled the java file and replaced it it gave me this error message

HTTP Status 500 -

type Exception report

message

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

exception

javax.servlet.ServletException: Error allocating a servlet instance
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      java.lang.Thread.run(Thread.java:619)

root cause

java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
      java.lang.ClassLoader.defineClass1(Native Method)
      java.lang.ClassLoader.defineClass(ClassLoader.java:621)
      java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
      java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
      java.net.URLClassLoader.access$000(URLClassLoader.java:56)
      java.net.URLClassLoader$1.run(URLClassLoader.java:195)
      java.security.AccessController.doPrivileged(Native Method)
      java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      java.lang.ClassLoader.loadClass(ClassLoader.java:252)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1302)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      java.lang.Thread.run(Thread.java:619)

root cause

java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet
      java.net.URLClassLoader$1.run(URLClassLoader.java:200)
      java.security.AccessController.doPrivileged(Native Method)
      java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      java.lang.ClassLoader.loadClass(ClassLoader.java:252)
      java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
      java.lang.ClassLoader.defineClass1(Native Method)
      java.lang.ClassLoader.defineClass(ClassLoader.java:621)
      java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
      java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
      java.net.URLClassLoader.access$000(URLClassLoader.java:56)
      java.net.URLClassLoader$1.run(URLClassLoader.java:195)
      java.security.AccessController.doPrivileged(Native Method)
      java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      java.lang.ClassLoader.loadClass(ClassLoader.java:252)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1302)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      java.lang.Thread.run(Thread.java:619)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
Apache Tomcat/6.0.18

any help
0
hatem_from_mesrAuthor Commented:
it work after a while with unstability I don't know why could you help in that
0
hatem_from_mesrAuthor Commented:
the following problem arise when recompiling the servlet after it have been worked

HTTP Status 500 -

type Exception report
 
message

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

exception

when
0
Gibu GeorgeChief Technology OfficerCommented:
Check if you have the servlet-api.jar in the <CATALINA_HOME>/lib folder
0
hatem_from_mesrAuthor Commented:
yes it's exist there
0
Gibu GeorgeChief Technology OfficerCommented:
The examples folder should be in the webapps and not in the <CATALINA_HOME>/lib. The webapps is the deployment folder
0
hatem_from_mesrAuthor Commented:
I tried it as you say but it does not work at all and keeping saying not available
0
Gibu GeorgeChief Technology OfficerCommented:
The directory structure should be like

<CATALINA_HOME>
                     |
                     |--webapps
                                  |
                                  |--testWebapp
                                            |
                                            |----- WEB-INF
                                                          |-- classes
                                                          |   |-- HelloWorldServlet.java
                                                          |   `-- examples
                                                          |       `-- HelloWorldServlet.class
                                                          `-- web.xml

Then you will be able to access the servlet using
 
http://localhost:8080/testWebapp/examples.HelloWorldServlet
with the servlet mapping given by you
0
hatem_from_mesrAuthor Commented:
did not work with me till I put the examples folder under <tomcat_home>/lib and made 500 internal error when recompile the class and replace for changes
0
hatem_from_mesrAuthor Commented:
I found this solution only
tomcat 5.5.27
have different structure
<tomcat_home>
   --------------------------common
   -------------------------------------------classes
which take the classes only and the webapps folder have the jsp and the deployment descriptor

what do you think about that
0
hatem_from_mesrAuthor Commented:
sorry classes under common
0
Gibu GeorgeChief Technology OfficerCommented:
The common is common for all the webapps deployed and is not for any specific web app. If you want to do it for a specific web app the nyou need to put in the webbapps/<webappname>/WEB-INF/classes
0
Gibu GeorgeChief Technology OfficerCommented:
In normal case the folder structure I gave works for tomcat. I think somehow tomcat got corrupted(may be some of the configuration files). Try reinstalling tomcat.
0
hatem_from_mesrAuthor Commented:
which one to download and install

       * Core:
              o zip (pgp, md5)
              o tar.gz (pgp, md5)
              o Windows Service Installer (pgp, md5)
        * Deployer:
              o zip (pgp, md5)
              o tar.gz (pgp, md5)


0
Gibu GeorgeChief Technology OfficerCommented:
Core
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hatem_from_mesrAuthor Commented:
thanks for help any way
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.