Hey guys in this article, you will learn how to display Hello World in JSP web application with easy to understand steps.
Read More:
- Check the Complete JSP Tutorials
- Check the Complete Spring Boot Tutorials [100+ Examples]
- Check the Complete Spring Boot and Thymeleaf Tutorial
- Check the Complete AWS Tutorial
- Check the Complete JavaServer Faces (JSF) Tutorial
- Check the Complete Spring Data JPA Tutorial
- Check the Complete Spring Security Tutorial
- Check the Javascript Projects for Beginners
- Check the Spring Boot JdbcTemplate Tutorials
Table of Contents
Overview
- JSP is a HTML web page which contains some Java code in between
- We can add Java code in between to display the dynamic content
- JSP page is processed on the server
- The JSP file should be place inside the WebContent folder
- JSP page should have the extension
.jsp
<p> The current date and time is <%= new Date(System.currentTimeMillis()) %> </p>
Create a Dynamic Project
To create a new dynamic project click on File, choose New, select Dynamic Web Project
Note: If you don’t find Dynamic Web Project then choose other and search for Dynamic Web Project, it will be present under the Web folder
Enter the Project name, Select the Dynamic web module version (At the time of writing this post, latest web module version is 4.0)
Create a JSP file
Create HelloWorld.jsp
file under the WebContent folder and add the following content
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Hello World</h1>
<p>Current date and time is <%= new Date(System.currentTimeMillis()) %> </p>
</body>
</html>
Run the file
Right click on the File, choose Run as, choose Run on Server, It will ask you to configure the server
Select Tomcat v9.0 under the Apache folder and Click on the add option to add the server
Provide the tomcat path and click Finish
Tip: Download the Apache tomcat from https://tomcat.apache.org/download-90.cgi
Once the tomcat is added to your workspace, Right click on the File, choose Run As, choose Run on Server.
It will open on the default web browser and you will see the following output
That’s it for this post, if you like this post, please share this post with your friends and collogues and also share this on your social media profiles.