Apache Tomcat Orientation (by Luis Cruz)

coldwaterphewServers

Nov 17, 2013 (3 years and 7 months ago)

102 views

Apache
Tomcat Orientation

(by Luis Cruz)



Setting up Tomcat in the JCCL

1.

From the Start menu, go to Programs, Developer Tools, Apache Tomcat 5.0

2.

Click on the
setup.bat

link. Only do this once for the entire semester.

3.

Create the Startup/Shutdown Server Sh
ortcuts on your desktop.

Create Shortcuts from



C:
\
Program Files
\
Tomcat 5.0
\
bin
\
startup.bat



C:
\
Program Files
\
Tomcat 5.0
\
bin
\
shutdown.bat


Downloading and Installing Tomcat at Home


1.

Go to
http://jakarta.apache.org/site/binindex.cgi

and scroll down until you
see
Tomcat 5.0.xx and download Tomcat 5.0.xx.EXE

2.

Run jakarta
-
tomcat
-
5.0.xx
.exe

and follow the steps to install on your machine.



Customizing an IDE for
S
ervlets


1.

Netbeans
-

http://www.cs.fiu.edu/~downeyt/cgs4825/netbeans.html

2.

JCreator
-

http://www.cs.fiu.
edu/~downeyt/cgs4825/jcreator.html



Modifying Configuration Files

(After Modifying Files Restart the Server)


server.xml

Modifications

need to be made to server.xml to allow Tomcat to automatically
reload a servlet if its .class file has been modified. O
pen server.xml in a text editor

(notepad.exe)

and look for the comment


<!
--

Define
the top level container in our container hierarchy

...

...
--
>


After the close of the comment, and before any other tags, add the following tag


<DefaultContext reloadabl
e="true” />




web.xml

The only change to make to the web.xml file is to uncomment the code for the
invoker servlet. The invoker servlet allows Tomcat to execute any servlet that is
in a directory. Without the invoker servlet, you would need to add info
rmation
about every servlet to be run in the web.xml file of that directory. Open web.xml
in a text editor and look for the following


<!
--

<servlet mapping>


<servlet
-
name>invoker</servlet
-
name>


<url
-
pattern>/servlet/*</url
-
pattern>

</servlet
-
mapping>

--
>


Remove the comments before and after this so that it looks like


<servlet mapping>


<servlet
-
name>invoker</servlet
-
name>


<url
-
pattern>/servlet/*</url
-
pattern>

</servlet
-
mapping>


In Tomcat 5, you also have to uncomment the corresponding servlet
element at
the top of web.xml, as below:



<servlet>


<servlet
-
name>invoker</servlet
-
name>


<servlet
-
class>


org.apache.catalina.servlets.InvokerServlet


</servlet
-
class>


...


</servlet>



Creating your own Web
Application

(webapp)


Web Applications are directories that have a specific structure and contain some required
files. The easiest place to put these is in the webapps directory of Tomcat.


1.

Create a subdirectory of webapps and name it cgs4825.

2.

Create a s
ubdirectory of cgs4825 and name it WEB
-
INF.

3.

Create a subdirectory of WEB
-
INF and name it classes.

4.

Create a text file in the WEB
-
INF directory and name it web.xml. Place the
following in the web.xml file







<?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>


</web
-
app>


All Web Applications have this basic structure. The next step is to let the servlet engine
know that th
is application exists.


1.

Edit server.xml in the conf directory.

2.

Find where you already added the DefaultContext.

3.

After the close of the DefaultContext tag, add the following


<Context path="/cgs4825" docBase="cgs4825" reloadable="true" crossContext="t
rue"
debug="0"/>


4.

Restart Tomcat


Now you can create a servlet in the cgs4825 directory and execute it through Tomcat.



Tomcat Tutorials


http://www.coreservlets.com/Apache
-
Tomcat
-
Tutorial/


Tomcat Documentation


http://jakarta.apache.org/tomcat/

http://
jakarta.apache.org/tomcat/tomcat
-
5.0
-
doc/index.html

http://www.cs.fiu.edu/~downeyt/c4825.shtml


Apache 2.0 Documentation


http://httpd.apache.org/docs
-
2.0/