This site provides useful information regarding installation of Tomcat server. The steps by step of the installation are shown properly. Every step will followed by a capture of screen that enable user to better understand what they are doing currently and what they will be doing after. This will attract new user of Tomcat that are using Window platform to further reading on this site before continuing into installation.
In the subtitle 'Deployment of jsp or servlet in tomcat', user will be provided with example of creating first servlet. This is helpful for new user to test the example given and get knowledge from that before going in depth.
Download JDK or JRE from sun website
http://java.sun.com/javase/downloads/index.jsp
Sun provides different executable file for Windows and Linux operating system version. Sun provide JDK for Linux in .bin or tar.gz format, and for Windows .exe format. After downloading file from sun, install JDK simple double click or through command prompt .

Default installation directory for java in Windows is Program file à Java, and Linux
/opt. Tomcat 5.5.17 version requires at least java1.5 version.

When jdk is installed in default location, need to configuration the environment variable
Environment variable is next to set java home in system environment. This will help to know others application where is java is installed and where java file have to compile. JAVA_HOME variable name needs to set in environment variable as variable name and variable value as the java home directory c:\ jdk1.5.0.
Step to do this setting, go to my computer icon and right click and go to properties

My computer->right click->properties->

Advance tab->environment variables ->

User variables –> New

Click on new button and new pop up will open.
In variable value, enter your java path where java is installed in system.
Tomcat installation
Tomcat installation is of two types. Apache provides self installer for tomcat installation.This tomcat is in executable binary file. Download,and install, self installer do all work automatically.Second is source code extractor. This tomcat installation is also easy as self installer. Before tomcat installation, check all jvm, java, and environment path set properly.
Apache tomcat is freely available from apache jakarta site
http://archive.apache.org/dist/tomcat/tomcat-5/
According to per requirement, tomcat is downloaded in form of binaries or source code.
We are using zipped pack for windows installation. Download zipped binaries code latest one from this site.Unzip this code and c:\ drive and anywhere desired directory
After unzipped directory system will like that

This is means that tomcat is installed properly and ready to run web server. Open bin directory and double click on startup.bat file. Startup.bat will open in dos command prompt

After starting tomcat, check tomcat in web browser by typing localhost:8080 in address bar
http://localhost:8080/

This page shows Tomcat is running properly in your system.
Apache Tomcat Configuration Tomcat use 8080 port instead of 80 port. User can easily change default port from tomcat. Open c:/tomcat/config/server.xml folder in tomcat installed and open server.xml file.
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
<!-- Note : To disable connection timeouts, set connectionTimeout value
to 0 -->
In connector port change 8080 to 80, now save this save and shutdown.bat tomcat and startup.bat tomcat.This time user need not to write 8080 port in http://localhost/
Servlet invoker
Servlet container of tomcat engine doesn’t start automatically. WEB-INF deployment descriptor needs to tell servlet engine, where your servlet and mapping of servlet.This is is can be done without any setting through servlet invoker. We just need to uncommented the code in web.xml in config folder.Servlet invoker automatically load servlet in context and map it.
Open c:/tomcat/config/web.xml and edit this code as shown.
First uncommented invoker then servlet mapping
<!-- -->
<!-- debug Debugging detail level for messages logged -->
<!-- by this servlet. [0] -->
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>
org.apache.catalina.servlets.InvokerServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
also uncommented the servlet mapping
<!-- The mapping for the invoker servlet -->
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
<!-- The mapping for the JSP servlet -->
If you are using tomcat 6, need to define privileges for context. In tomcat 5.5.x version no need to define privileges for context. Tomcat 5.5.x take automatically.
Privileges setting can be done in tomcat/conf/context.xml file. Add this line
<Context reloadable="true" privileged="true">
All jsp and html page should be kept in C:\tomcat\webapps and create your own folder or keep jsp file under default directory ROOT. We would like to create new folder in webapps as home and keep all files in this folder. In home folder create WEB-INF folder and inside this also create two folder named as classes and lib and keep web.xml in WEB-INF.
In classes folder, all servlets and javaBeans should keep,Classes folder generally contains class file and java file and when servlet engine starts, all java and class file loaded in tomcat through bootstrap.jar which is in bin folder. Create a first servlet example see example
Deployment of servlet
Servlet deployment needs to map in deployment descriptor, if you have not enabled servlet invoker. Descriptor give us more feature of deploying servlet with user defined URL context path.
All servlet needs to compile manually and copy to WEB-INF/classes folder.
Descriptor file is web.xml which keeps all information of servlet and taglib’s tld
Suppose we are deploying TestServlet servlet at default package.
WEB-INF/classes/TestServlet.class
Make a file
WEB-INF/web.xml
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/servlet/TestServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Deployment of Application
|