In this article, we are going to teach you how to run your first JSP program.
Before we execute a JSP program, we need to make sure that our Tomcat web server is up and running. Let's see how to do that.
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 browser and enter the URL -
http://localhost:8080/, which opens the window with a congratulatory message for successful installation and execution of Tomcat.
Now as our Tomcat web server is running, let's create a JSP webpage.
This is my first JSP page.
A JSP webpage ends with a .jsp extension, hence we have named this file A.jsp.
Where to save the JSP(.jsp) file?
In order to allow Tomcat web server to easily find this JSP file and execute it, we can store this file in any of the
two locations -
1) in the ROOT folder(stored within webapps folder of your Apache Tomcat directory).
Path to the ROOT folder is - C:\apache-tomcat-9.0.2\webapps\ROOT
2) Or, We could create a new folder(with any name) in the webapps folder of Tomcat and store this A.jsp webpage in it.
For example, we can create a new folder first jsp within the webapps folder of Tomcat and store A.jsp within it.
Executing the JSP file
Next, we need to enter the URL of this JSP document in the address bar of our web browser. This URL may look a little
different depending on where you store this file.
1) If JSP file is stored in the ROOT folder at location - "C:\apache-tomcat-9.0.2\webapps\ROOT"
The URL to execute this JSP webpage would be http://localhost:8080/A.jsp
2) If JSP file is stored in the a new folder created by you(within webapps folder) then we need to give the full path to the file(including
the new folder which contains this JSP file)
For example, if we stored A.jsp in the folder first jsp then the URL to execute this file would be