← Back to list

Let’s make a web app using Java EE

I have to make a web project using Java EE for my BSc first semester advanced programming module. So I thought to explain how I developed…

Ramitha Heshan · 2025-08-20 10:12 · 0 claps · 3.8 min read
#java #java-ee #web-development #software-engineering #advanced-programming
Open on Medium ↗
Wiki topics: 💻 · Programming 🌐 · Web Development

Let’s make a web app using Java EE

I have to make a web project using Java EE for my BSc first semester advanced programming module. So I thought to explain how I developed the project step by step. So let’s do this.

Project Setup.

You can go to File and select the ‘New Project’. Then you will fall into the below page. According to the screenshot below, you have to select Jakarta EE as the generator type. And then the template is ‘Web application’. And here, I have selected ‘Tomcat’ as my application server.

After filling in correctly, you can press the ‘Next’ button. Then you will fall into the below page. That is the page that lets us select the version of Jakarta EE. Here I have used Jakarta EE 9.1 version.

After selecting the Jakarta version, you can hit the ‘create’ button. And then your project will be created. After creating the project, your IntelliJ IDE can be seen like this.

Now you can run your application using the top run button. If the project runs successfully, your web browser shows a text called “Hello World!”.

Database Connection

We are developing a billing system for an educational institute. So we have to store book details somewhere. In this project, I am dealing with MySQL. So, first, I have to add the MySQL dependency to the pom.xml file. To do that, you can go to this link and copy the dependency. And then, you can paste in the dependencies section of the pom.xml file. Below is my updated pom.xml file.

We can create our database right within IntelliJ. To do that, you have to create a ‘.sql’ file and write the SQL queries in it. After, you will see a message at the top of the window called “Configure data source” like below.

Click it and select MySQL as the data source. And then you will fall into this window. Here, you have to fill in your SQL details like port, username, and password. If you have not changed those, they are as below.

After filling in the details correctly, you can test your connection to see whether it is ok or not using the ‘Test Connection’ text. If the connection is correct, you will see a message like above.

After adding that, you will see a run icon like above. Then you can go to your SQL script file and hit that run button. Then your SQL script is run and creates your database and tables.

Now we need to create a Java class to communicate between the web app and the database. For that, I have created a class called “DBConn.java”.

package org.example.pahana_edu;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConn {
    private static final String URL = "jdbc:mysql://localhost:3306/pahana_edu";
    private static final String USER = "root";
    private static final String PASSWORD = "";

    private static DBConn instance;

    private DBConn() {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        }
        catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static synchronized DBConn getInstance() {
        if (instance == null) {
            instance = new DBConn();
        }
        return instance;
    }

    public Connection getConnection() throws SQLException {
        return DriverManager.getConnection(URL, USER, PASSWORD);
    }
}

We can keep the connection between the DB and the web app using this file. There is an important thing about this file. That is the singleton design pattern. So what is Singleton?

Singleton is a design pattern that can be used to ensure that only one instance of a class is created throughout the application. When considering the usage of this pattern, Logging Configuration settings and the Database connections can be pointed out as the usages.

When considering the code, I have created a variable called “instance” to store a single DBConn object. And I have create the constructor with the private access modifier. This means no other class can create a DBConn object directly. Then I have created a method called getInstance() and any class can call this method. This method is synchronized. This means only one thread can run this method at a time.

Because of the length of the article, I decided to explain the development structure in a separate article. Here, I intend to use the Layered Architecture (also called Multitier Architecture).


메타데이터
post_id
2a7071e2dbe5
slug
lets-make-a-web-app-using-java-ee-2a7071e2dbe5
url
https://medium.com/@ramitha33/lets-make-a-web-app-using-java-ee-2a7071e2dbe5
canonical_url
https://medium.com/@ramitha33/lets-make-a-web-app-using-java-ee-2a7071e2dbe5
author_url
https://medium.com/@ramitha33
status
ok
fetched_at
2026-07-19 21:04:01