Installing and Configuring Tomcat SSE
Downloading Tomcat l Download url: 4.0/release/v4.1.24/bin/ 4.0/release/v4.1.24/bin/ l Click on the link that says jakarta-tomcat LE-jdk14.exe to download tomcat The LE stands for lightweight edition, which runs on top of jdk1.4 or higher)jakarta-tomcat LE-jdk14.exe
Installing Tomcat l Double click on the self extracting file that you downloaded for tomcat l Click on “I Agree” for the license l Use “Normal” Install, i.e., use the components that are already selected – Simply click on the “Next” button l 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. l Will see the files being unpacked – may take a minute or so l 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. l Once all the files are installed, hit close to finish the installation. It should create a program group for tomcat.
Directory Structure of Web Application
Creating, Compiling and Executing a Servlet l Type the code using notepad l Save as a.java file in the following directory: C:\Program Files\Apache Group\Tomcat 4.1\webapps\examples\WEB-INF\classes l 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 l The.class file should reside in the classes directory l Executing a servlet
Configuring Tomcat l Enable the ROOT context Uncomment the following line in the file C:\Program Files\Apache Group\Tomcat 4.1\conf\server.xml l Turn on Servlet Reloading Find the following lines in server.xml Add the following line after the comment in C:\Program Files\Apache Group\Tomcat 4.1\conf\server.xml
Configuring Tomcat (Contd) l Enable the Invoker Servlet Uncomment the servlet-mapping element in the file C:\Program Files\Apache Group\Tomcat 4.1\conf\web.xml invoker /servlet/* l Set the JAVA_HOME Variable Create a system variable called JAVA_HOME and set it to C:\j2sdk1.4.0_02
Creating a New Web Application l Steps to create a new web application called “myapp” Create the appropriate directory structure Add 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
Creating the Directory Structure l Create a folder called “myapps” (or any other name you choose) within the install_dir/webapps folder l Create the “WEB-INF” folder within the “myapps” folder l Create the “classes” folder within the “WEB- INF” folder l For now, make sure that you don’t have web.xml file within the WEB-INF directory
Adding Context information l Need to edit the following file: install_dir/conf/server.xml l Find the line: l Add the following lines before the above mentioned line - Keep in mind that XML elements are case sensitive l Save the server.xml file <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"/>
Remaining Steps l Restart Tomcat l 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 l Test the servlet (say you created Hello.class)
Deployment Descriptor File – WEB-INF/web.xml l The install_dir/conf/web.xml file controls the behavior of all the web applications that are under the webapps directory l If you want a particular web application to behave differently, then you add the web.xml file within the WEB-INF directory l It is not absolutely necessary that you should have the web.xml file for the application l Among other things, the web.xml file may contain the values of parameters that would be used during servlet initialization (calling the init() method)