Installing and Configuring Tomcat SSE. Downloading Tomcat l Download url: 4.0/release/v4.1.24/bin

12
Installing and Configuring Tomcat SSE

Transcript of Installing and Configuring Tomcat SSE. Downloading Tomcat l Download url: 4.0/release/v4.1.24/bin

Page 1: Installing and Configuring Tomcat SSE. Downloading Tomcat l Download url:  4.0/release/v4.1.24/bin

Installing and Configuring Tomcat

SSE

Page 3: Installing and Configuring Tomcat SSE. Downloading Tomcat l Download url:  4.0/release/v4.1.24/bin

Installing Tomcat

Double click on the self extracting file that you downloaded for tomcat Click on “I Agree” for the license Use “Normal” Install, i.e., use the components that are already selected –

Simply click on the “Next” button Use the default location for installation directory - C:\Program Files\Apache

Group\Tomcat 4.1 Click on the “Install” button to begin the installation process.

Will see the files being unpacked – may take a minute or so Then you will get to the administrator login window where you can enter a

password to use for the administrator account. Leave the connector port to 8080 (you could type in another port number if you want, but for now, leave it as it is). Type in a password and write it down so that you will remember it.

Once all the files are installed, hit close to finish the installation. It should create a program group for tomcat.

Page 4: Installing and Configuring Tomcat SSE. Downloading Tomcat l Download url:  4.0/release/v4.1.24/bin

Directory Structure of Web Application

Page 5: Installing and Configuring Tomcat SSE. Downloading Tomcat l Download url:  4.0/release/v4.1.24/bin

Creating, Compiling and Executing a Servlet

Type the code using notepad Save as a .java file in the following directory:

C:\Program Files\Apache Group\Tomcat 4.1\webapps\examples\WEB-INF\classes

Compile the class using javac• Should have the PATH setup for finding the jdk binaries• Should have the CLASSPATH setup for finding the servlet.jar file

The .class file should reside in the classes directory Executing a servlet

http://localhost:8080/examples/servlet/Hello

Page 6: Installing and Configuring Tomcat SSE. Downloading Tomcat l Download url:  4.0/release/v4.1.24/bin

Configuring Tomcat Enable the ROOT context

• Uncomment the following line in the file • C:\Program Files\Apache Group\Tomcat 4.1\conf\server.xml

• <Context path="" docBase="ROOT" debug="0"/>

Turn on Servlet Reloading• Find the following lines in server.xml

• <!-- Define properties for each web application. This is only needed if you want to set non-default properties, or have web application document roots in places other than the virtual

host's appBase directory. -->

• Add the following line after the comment in • C:\Program Files\Apache Group\Tomcat 4.1\conf\server.xml• <DefaultContext reloadable="true"/>

Page 7: Installing and Configuring Tomcat SSE. Downloading Tomcat l Download url:  4.0/release/v4.1.24/bin

Configuring Tomcat (Contd)

Enable the Invoker Servlet • Uncomment the servlet-mapping element in the file• C:\Program Files\Apache Group\Tomcat 4.1\conf\web.xml

• <servlet-mapping> • <servlet-name>invoker</servlet-name> • <url-pattern>/servlet/*</url-pattern> • </servlet-mapping>

Set the JAVA_HOME Variable• Create a system variable called JAVA_HOME and set it to C:\

j2sdk1.4.0_02

Page 8: Installing and Configuring Tomcat SSE. Downloading Tomcat l Download url:  4.0/release/v4.1.24/bin

Creating a New Web Application Steps to create a new web application called “myapp”

• Create the appropriate directory structure

• Add <Context> information for the new application to the server.xml file

• Restart Tomcat

• Add one or more servlets to the application

• Test the servlets

• To control the behavior of this application add web.xml file to the WEB-INF directory

• If a web.xml file is not provided for this application, the install_dir/conf/web.xml file will be used

Page 9: Installing and Configuring Tomcat SSE. Downloading Tomcat l Download url:  4.0/release/v4.1.24/bin

Creating the Directory Structure

Create a folder called “myapps” (or any other name you choose) within the install_dir/webapps folder

Create the “WEB-INF” folder within the “myapps” folder

Create the “classes” folder within the “WEB-INF” folder

For now, make sure that you don’t have web.xml file within the WEB-INF directory

Page 10: Installing and Configuring Tomcat SSE. Downloading Tomcat l Download url:  4.0/release/v4.1.24/bin

Adding Context information Need to edit the following file:

install_dir/conf/server.xml Find the line: <!-- Tomcat Examples Context --> Add the following lines before the above mentioned line - Keep in

mind that XML elements are case sensitive

Save the server.xml file

<!-- Tomcat myapp Context --> <Context path="/myapp" docBase="myapp" debug="0" reloadable="true" crossContext="true"> <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_myapp_log." suffix=".txt" timestamp="true"/> </Context>

Page 11: Installing and Configuring Tomcat SSE. Downloading Tomcat l Download url:  4.0/release/v4.1.24/bin

Remaining Steps

Restart Tomcat Add one or more servlets to the “myapp” application

• Create the servlet source file (.java file) in the install_dir/webapps/myapp/web-inf/classes directory

• Compile the source file using javac• Alternatively, you can put the source file(s) anywhere you want, compile

them, and then move the .class files into the install_dir/webapps/myapp/web-inf/classes directory

Test the servlet (say you created Hello.class)• http://localhost:8080/myapp/servlet/Hello

Page 12: Installing and Configuring Tomcat SSE. Downloading Tomcat l Download url:  4.0/release/v4.1.24/bin

Deployment Descriptor File – WEB-INF/web.xml The install_dir/conf/web.xml file controls the behavior of

all the web applications that are under the webapps directory

If you want a particular web application to behave differently, then you add the web.xml file within the WEB-INF directory

It is not absolutely necessary that you should have the web.xml file for the application

Among other things, the web.xml file may contain the values of parameters that would be used during servlet initialization (calling the init() method)