Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help to set up Tomcat for the first time

Status
Not open for further replies.

thelordoftherings

Programmer
May 16, 2004
616
IL
Hello,

I've created a "hello world" servlet, compiled it and now I need help in activating it.
I am using Tomcat 4.01 on Windows 98 with JDK1.4.
Can someone please guide me, step by step, how do I configure Tomcat and how do I activate my first servlet example?
 
OK, so here is a example servlet :


Note that it is in a package "mypackage". This is important.

When you have compiled it, then place it in your ROOT webapp directory (use ROOT because it is good for learning), so put it in :

TOMCAT_HOME/webapps/WEB-INF/classes/mypackage

The edit your web.xml file in TOMCAT_HOME/webapps/ROOT/WEB-INF

Add these lines :
Code:
        <servlet>
                <servlet-name>MyServlet</servlet-name>
                <servlet-class>mypackage.MyServlet</servlet-class>
                <load-on-startup>1</load-on-startup>
        </servlet>

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

You can then access your servlet like this :


--------------------------------------------------
Free Database Connection Pooling Software
 
Two more questions:
1. Shouldn't I set the CATHALINA_HOME variable as well ?
2. What does the web.xml uses for ?
 
Yes you should set your CATALINA_HOME to your install directory of tomcat :

DOS :
set CATALINA_HOME=C:\wherever

Linux/UNIX
export CATALINA_HOME=/wherever

web.xml allows you to map servlets, set up webapp specific parameters, set welcome-files and so on.

--------------------------------------------------
Free Database Connection Pooling Software
 
Hey,

You told me to put the compiled class at:
TOMCAT_HOME/webapps/WEB-INF/classes/mypackage

Inside WEB-INF I don't have the classes directory and even when I create it and put the compiled file there the Tomcat can't find it, I receive this error (My servlet name is Hello):
Apache Tomcat/4.0.1 - HTTP Status 404 - /servlet/Hello
 
Sorry, typo :

TOMCAT_HOME/webapps/WEB-INF/classes/mypackage

should be :

TOMCAT_HOME/webapps/ROOT/WEB-INF/classes/mypackage


--------------------------------------------------
Free Database Connection Pooling Software
 
Still doesn't work...
I receive:
Apache Tomcat/4.0.1 - HTTP Status 404 - /servlet/Hello
Any ideas?
 
Post your :

- directory structure of webapps/ROOT
- Your web.xml
- The URL you are using.

--------------------------------------------------
Free Database Connection Pooling Software
 
It is working now!
I had to configure the TOMCAT_HOME to be the tomcat's directory and now it is working.
Although, it is working even if I remove the web.xml configuration that you told me to put. Why is that? If it is working without it, why do we need to configure it for?
 
You may have the invoker server in conf/web.xml enabled, or tomcat may be caching your web.xml.

It is always a good idea to map your servlets in web.xml, you'll have problems down the line if you don't ...

--------------------------------------------------
Free Database Connection Pooling Software
 
web.xml configures web applications, server.xml configures the server.

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top