Creating a new dynamic web project in Eclipse IDE

  •  
  •  
  •  
  •  
  •  
  •  

Hello friends, in this tutorial we will learn how to create a new dynamic web project in eclipse IDE. Creating a new dynamic web project in Eclipse IDE is very easy and simple, you have to follow some steps and Eclipse will build a new dynamic web project for you within a couple of minutes. And so for that, you need to download the Eclipse IDE which supports Java EE and Apache Tomcat to creating a new dynamic web project.

Creating a new dynamic web project in eclipse IDE

Prerequisites:

Extract the Eclipse IDE and Apache Tomcat to some folder for installing them.

Creating a new dynamic web project in Eclipse IDE

Click on File->New->Dynamic Web Project. It will open the below dialog window.

Create dynamic web project in Eclipse IDE

Again it will open a new dialog window like below. Enter “DynamicWebProject” as the project name or anything else what you want and set your settings as below screenshot. In my case I used Apache Tomcat v7.0, you can use the latest version of Apache Tomcat. And the last click on the “Next >” button.

Create dynamic web project and its settings

Next set the “src” folder in the build path and click on the “Next >” button.

Necessary settings for creating dynamic web project in Eclipse IDE

In the Web Module window check “Generate web.xml deployment descriptor” and click on “Finish” button.

Generate web.xml deployment descriptor during dynamic web project creation
Now Eclipse IDE will generate the following web project and the default structure is as shown in the below image –

Default project structure after creating dynamic web project in Eclipse IDE

Now create a new JSP file and named it “index.jsp” by right-click on the “DynamicWebProject” or “WebContent” folder and choose File->New->JSP File. It will prompt a new window and will ask you the name of the file, write “index.jsp” and click “Finish”. Now if you look carefully in the “WebContent” folder you will see there “index.jsp” file.

File:- index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
  
</body>
</html>

Write JSP code

Write your own JSP code within the JSP file. In the below script you can see that within JSP scriptlet tag <% %> I have written some Java code which will display the current Date and Time.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*, java.text.*" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My first dynamic web project</title>
</head>
<body>
  <h1 align="center">Welcome to my first dynamic web project in eclipse</h1>
  <h2 align="center"><%= "Mitrajit's Tech Blog" %></h2>
  <%
  Date date = new Date();
    SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy E hh:mm:ss a");
  %>
  <h3 align="center">Current date & time: <%=ft.format(date) %></h3>
</body>
</html>

All setup is done. Now it is time to test run the newly created dynamic web project. Right-click on the project folder and choose Run As -> Run as Server.

Run your dynamic web project in Eclipse IDE

Now after successfully build, the dynamic web project will open automatically into the web browser or within the eclipse browser based on your eclipse web browser settings. Or you can run the program by entering the following URL into the browser address bar — http://localhost:8080/DynamicWebProject/

Run and deploy your first dynamic web project in web browser

About Mitrajit

One thought on “Creating a new dynamic web project in Eclipse IDE

Leave a Reply

Your email address will not be published. Required fields are marked *

Prove you are a human *