Before we learn how to create our first Servlet program, we need to know that much of the support for developing the web applications based on the Java Servlet technology does not come with the core Java,
hence, we have to include the path to a file named
servlet-api.jar in our classpath, System Variable.
The servlet-api.jar file comes within the lib Folder of Tomcat installation folder.
Let us set show you how to set the our System Variable named - classpath.
In order to set classpath we need to open the menu of Environment variables. To do this, 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 classpath system variable .
Next, we will explain how to set Environment variables.
Setting up the classpath to servlet-api.jar
Setting the classpath system variable -
The classpath variable should be set to the location of the
file servlet-api.jar, located within the lib folder of Tomcat installation folder.
For example, in our case we have installed Tomcat Web Server within the C: Drive, hence the path to the servlet-api.jar is - C:\apache-tomcat-9.0.2\lib\servlet-api.jar
To do this, within the System Variables section in the Environment Variables menu, first select the classpath system variable and then
click the Edit button(highlighted in the picture below).
Clicking the Edit button opens a new window, where you need to add the
path to the servlet-api.jar to variable value as shown in the figure below.
In our case, it is - C:\apache-tomcat-9.0.2\lib\servlet-api.jar. Please note, this path ends with a semicolon ; (please take a look at the picture below)
Click the OK button to save the updated classpath settings.