JSP stands for JAVA Server Pages. It is JAVA Code inside HTML. It is useful technology for presentation layer or View.
Using JSP, developer can generate dynamic content on web pages.
In order to start with JSP, first you need to have application server that can handle JSPs. Apache Tomcat server contains JSP container. If you do not have Server installed on your machine, please download and install it from here.
I assume that you have successfully downloaded and installed Apache Tomcat server on your computer.
For simplicity, I am going to use Eclipse IDE here.
Follow these steps to create your first JSP and run it on Tomcat Server.
Step 1: Create new project.
Open Eclipse IDE and create a new Dynamic Web Project. Click on File --> New --> Dynamic Web Project as shown in the image below.
Step 2: Assign name to the project.
Once you click on the Dynamic Web Project in step 1, new window will open as shown in the image below. Give some meaningful name to the project. I name it as JSPTest. Continue click on next button until Eclipse create a new project and display it on Project Explorer on left hand side.
Step 3: Create new server instance.
Click on the Server tab. It should be near to console tab. If it is not available, change the perspective to JavaEE. Right Click on the server tab, click on new and than click on server. Please refer image shown below.
Step 4: Select Server.
Once you click on server in the previous step, eclipse will open new window, where you can specify the type of server and version of it. Since we already downloaded and installed Tomcat Server on our computer, select Apache --> Tomcat V6.0 Server as shown in the image below.
Step 5: Select Tomcat Installation Directory
Next step is to select Tomcat Installation Directory. In my computer, it is under C drive so I specified path of Tomcat Installation Directory to C:\apache-tomcat-6.0.035
Step 6: Move project to configure on server.
Next step is to move the project to configure it on server. Refer image shown below:
Step 7: Create JSP on the project.
Open the project. You will be able to see folder name WebContent. Right click on that folder, click on new and than click on JSP. Give some meaningful name to JSP. I name it hello.jsp
You will see some pre existing HTML code on that page. You can edit it or write new HTML code. For now, just write something withing <body> and </body> tag.
Step 8: Run JSP on server.
Right click on the project, click on Run As and than click on Run on Server. Eclipse will start server. You may see error 404, if you do not have index page on the project. But for now, you need not to worry about it. At the end of url, append your jsp. For example, jsp name is hello.jsp so put /hello.jsp at the end of http://localhost:8080/JSPTest/hello.jsp and refresh browser.
You will see the line printed on browser, which you entered on JSP within <body> and </body> tag.
Congratulations....you have successfully run your first JSP on server.