Java is essential to execute JSP code. Hence, before you run Tomcat server to execute your JSP code,
you need to set the environment variables of Java to make sure that Tomcat is able to find Java in order to execute the JSP code. In order to set environment variables, we need to type in a windows command sysdm.cpl in the search box of the Windows Operating System(Windows 7 to Windows 10), and press Enter to open the a window of System Properties.
The next window of System properties open up, we need to click on its tab Advanced.
In this tab Advanced, we need to click on the Environment Variables , in order to set the environment variables for Tomcat web server.
Next, we will explain how to set Environment variables.
Steps to setup Environment Variables for Apache Tomcat Server -
Set CATALINA_HOME environment variable -
The CATALINA_HOME environment variable should be set to the location of the
root directory of the "binary" distribution of Tomcat. In our case, the "binary" distribution of Tomcat is located in
the C: Drive. To do this, under the System Variables in in the Environment Variables Menu, click the New button(highlighted in the picture below).
Clicking the New button opens a new window, where you need to set the variable name to CATALINA_HOME and
variable value to
C:\apache-tomcat-9.0.2 (the location of Tomcat in your system) as shown in the figure below.
Setting the JRE_HOME or JAVA_HOME environment variable -
This variable is used to specify the location of a Java Runtime
Environment(JRE) or a Java Development Kit(JDK), which is required to start Tomcat web server. We have set JRE_HOME
environment variable to the location of our Java Runtime Environment(JRE) in our system.
Again, in the window of Environment Variables, clicking the New to set the variable name to JRE_HOME and
variable value to
C:\Program Files\Java\jre1.8.0_144 (the location of Java Runtime Environment(JRE) in your system) as shown in the figure below.
Starting the Tomcat web server
After setting these environment variables, we are going to start Tomcat. For this, you need to open the Command Prompt and
go to the bin directory of the Tomcat folder present in the C: Drive, such as C:\apache-tomcat-9.0.2\bin
and now you type startup(a command which starts the Tomcat Server) and press Enter.
Pressing the Enter after startup command starts the Tomcat web server as shown below.
That's it! Tomcat web server is up and running and we don't have to close the server window till the time we are working
Making sure that Tomcat is running
Just to make sure that Tomcat web server is running is to open your web browswer and enter the URL -
http://localhost:8080/, which opens the window with a congratulatory message for successful installation and execution of Tomcat.
8080 is the port number on which Tomcat Server runs by default.
You can change this port number anytime you wish by opening the server.xml file in "C:\apache-tomcat-9.0.2\conf" location and specifying a new port number for the
variable Connector port.
Just so you know
Additionally, you can also fine the directions of setting the environment variables for Tomcat in the file "running.txt"
that comes included with Tomcat.