APACHE TOMCAT 6
APACHE TOMCAT 7
JAVASERVER FACES (JSF)
GENERAL JAVA PROGRAMMING
JAVA 8 LAMBDAS & STREAMS
AJAX & GWT
INTERMEDIATE SERVLETS & JSP
ADVANCED SERVLETS & JSP
HIBERNATE & JPA
WEB SERVICES WITH AXIS2
TUTORIALS IN CHINESE
TUTORIALS IN JAPANESE
ABOUT THE INSTRUCTOR
JSF 2 & PRIMEFACES
JAVA 7 & JAVA 8 PROGRAMMING
AJAX (w/ JQUERY, HTML5, ETC.)
RESTful WEB SERVICES
HIBERNATE & JPA
SERVLETS & JSP
PUBLIC TRAINING SCHEDULE
Apache Tomcat 6 Tutorial
For most people, the easiest way to get started with Tomcat is to use a preconfigured version as described in these links:
However, if you want to customize the configuration, this page provides more detail.
Configuring Tomcat involves four main steps and three optional steps:
Details of each step are given below. If you use Eclipse, re-register the server after changing the configuration files.
Go to http://tomcat.apache.org/download-60.cgi and download and unpack the zip file for the current release build of Tomcat 6. You specify the top-level directory (e.g., C:\) and the zip file has embedded subdirectories (e.g., apache-tomcat-6.0.28). Thus, C:\apache-tomcat-6.0.28 is a common resultant installation directory. Note: from this point forward, I'll refer to that location as install_dir. For Windows, there is also a .exe installer; I prefer the .zip file, but see the .exe installer section for notes on the differences between the two.
Alternatively, you can use my preconfigured Tomcat version:
This preconfigured version already has the port changed to 80, servlet reloading enabled, the invoker servlet turned on, and directory listings allowed. It also comes with a sample development directory, sample autoexec.bat file, startup/shutdown shortcuts, and shortcuts for deploying applications.
If you use Tomcat with Eclipse, you can skip this step.
However, if you compile and deploy manually, you must set the
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_21
On recent Windows versions, it is generally better to use the Control Panel
than to use autoexec.bat. Go to the Start menu, select Control Panel,
choose System, click on the Advanced tab, press the Environment Variables
button at the bottom, and enter the
Assuming you have no other server already running on port 80, you'll find it convenient to configure Tomcat to run on the default HTTP port (80) instead of the out-of-the-box port of 8080. Making this change lets you use URLs of the form http://localhost/blah instead of http://localhost:8080/blah. Note that you need admin privileges to make this change on Unix/Linux. Also note that some versions of Windows automatically start IIS on port 80. So, if you use XP and want to use port 80 for Tomcat, you may need to disable IIS (see the Administrative Tools section of the Control Panel).
To change the port, edit install_dir/conf/server.xml
and change the
<Connector port="80" protocol="HTTP/1.1" ... >
You can also:
The next step is to tell Tomcat to check the modification dates of the class files of requested servlets, and reload ones that have changed since they were loaded into the server's memory. This slightly degrades performance in deployment situations, so is turned off by default. However, if you fail to turn it on for your development server, and you compile/deploy manually, you'll have to restart the server every time you recompile a servlet that has already been loaded into the server's memory. Since this tutorial discusses the use of Tomcat for development, this change is strongly recommended. Note that Eclipse takes care of this for you automatically.
To turn on servlet reloading, edit Edit install_dir/conf/context.xml and change
<Context reloadable="true" privileged="true">
Note that the
You can also:
The invoker servlet lets you run servlets without first making changes to your Web application's deployment descriptor (i.e., the WEB-INF/web.xml file). Instead, you just save your servlet (Eclipse) or drop your servlet into WEB-INF/classes (manual deployment) and use the URL http://host/servlet/ServletName (or http://host/webAppName/servlet/packageName.ServletName once you start using your own Web applications and packages). The invoker servlet is extremely convenient when you are learning and testing out various APIs. You probably want to enable it when learning, but you should disable it again before deploying any real applications.
To enable the invoker servlet, uncomment the following
<servlet> <servlet-name>invoker</servlet-name> <servlet-class> org.apache.catalina.servlets.InvokerServlet </servlet-class> ... </servlet> ... <servlet-mapping> <servlet-name>invoker</servlet-name> <url-pattern>/servlet/*</url-pattern> </servlet-mapping>
In Tomcat 6 (but not Tomcat 5.5), you also need the
You can also:
In previous Tomcat versions, if you entered a URL ending in a slash (/) and there was no welcome-file in the directory (or servlet-mapping that matched the URL), Tomcat displayed a directory listing. In Tomcat 6, the default was changed from true to false for these directory listings. Many developers find it convenient to turn directory listings back on so that when practicing or during the early project development phases they can simply type in a directory and then click on an HTML or JSP page. To make this change, edit install_dir/conf/web.xml and change the init-param value of listings for the default servlet, as below. Do not confuse this Apache Tomcat-specific web.xml file with the standard one that goes in the WEB-INF directory of each Web application.
<servlet> <servlet-name>default</servlet-name> <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>0</param-value> </init-param> <init-param> <param-name>listings</param-name> <param-value>true</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
You can also:
If you are using Microsoft Windows and do not use Eclipse or another IDE, you can download a .exe Tomcat installer instead of the .zip file discussed in this tutorial. In my opinion, it is not worth the bother to do so, but some non-Eclipse users like it. If you use it, note these differences:
|© 2015 coreservlets.com | Design by TBIQ | Java hosting from Kattare|