Master java skills

First JSP application

In this tutorial, we will create a simple jsp application. We will use maven as build tool and Tomcat 8.5 server.

Step 1 – Create a simple maven project

Enter the details

Step 2 – Add below dependency

<dependency>
	<groupId>javax.servlet</groupId>
	<artifactId>javax.servlet-api</artifactId>
	<version>4.0.1</version>
	<scope>provided</scope>
</dependency>

Full pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.sks</groupId>
  <artifactId>my-first-jsp-app</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  
  <dependencies>
  	<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>4.0.1</version>
			<scope>provided</scope>
		</dependency>
  </dependencies>
  
</project>

Step 3

Now, this is a simple maven project. We need to convert this to dynamic web project. Follow the below navigation.

Right click on the project -> Properties -> Project Facets -> Convert to Faceted Form

Now tick the check box Dynamic Web Module. Make sure that you choose Dynamic Web Module as 3.0 due to its compatibility with Tomcat 8.5 version. Also make sure that java version is chosen as 1.8.

Click on Apply and Close. This step will create webapp folder like below

Step 4

Create below jsp page under webapp folder

Note -> This is a plain jsp page which only has html content.

home.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Home Jsp</title>
</head>
<body>
	<p>Welcome to the first jsp page</p>
</body>
</html>

Step 5

Add the application to Tomcat. If you don’t know how to configure and deploy an application on Tomcat, click below.

Step 6

Run the server and hit the url

http://localhost:8080/my-first-jsp-app/home.jsp