INTRODUCTION TO WEB APPLICATIONS

spring

It is because of the Spring Framework that we can make Web Applications. Let us immediately clarify what Web Apps are with the support of some images.

Funzionamento web application

LET’S ANALYZE THE FIGURE ABOVE

The moment we type an address into the browser, the browser itself uses the Internet as its medium and uses an HTTP protocol, or HTTPS when the data is encrypted, to send the request. In doing this it sends a specific request to a server, a computer that can fulfill requests, in this case we requested the index resource and the server returns the HTML page, CSS with sometimes some JavaScript in the response sent to the client.

CLIENT REQUEST ANALYSIS

Let’s take a good look at the requested resource. http is the protocol, www.miosito.com identifies the server. When we type this address into the browser www.miosito.com is passed to another server, the DNS (Domain Name System), which has mapped internally this mnemonic address, easy for a human being to understand, into an IP address, which is then the IP address of the server. Once the request arrives at the server with the IP address resolved by DNS, the ball is passed to the Web Server, in our case Tomcat, which turns the request over to the Web Application, which understands that the Client has requested the index resource, if necessary draws data from a database and returns the response in HTTP, or HTTPS format, but it can also be JSON or XML.

TECHNOLOGIES FOR CREATING WEB APPS

Tecnologie

Web applications created with Spring decrease the complexity of the work, minimizing implementation efforts by programmers.

Caratteristiche Spring Framework

HOW SPRING HANDLES CLIENT REQUESTS

The first step is to enter the address into our browser. Let us see with a picture the infrastructure with which Spring serves resources to a certain client.

Gestione richieste in Spring MVC

The Servlet Dispatcher analyzes the request and checks which resource we are requesting, activates the Controller that manages that resource, and returns the index resource model. We can understand the model as the raw version of the data to be returned to the client. At this point the ball passes to another fundamental Spring element, the View Resolver, which will have the task of creating the view, i.e., our web page in HTML, CSS, JAVASCRIPT format using JSP (Java Server Page) as technology and returns the response to the client.

CREATION OF THE FIRST TEST PROJECT

I bring you a helpful video in creating the project.

CREATION OF JAVA CONFIGURATION CLASSES

When we go to request a given resource we use the HTTP protocol and the GET method. It is the first step. The Servlet Dispatcher will act as the interface between our request and the resource. The first step in our small example application will be to configure the Dispatcher Servlet. The code explains the procedure step by step.

Dispacher Servlet

Let’s look at the code of the most important configuration class.

Configurazione

INDEX CONTROLLER CREATION

Now we are going to configure the controller, as I already told you the Servlet Dispatcher has to go and find a controller that can handle the request. Finally, let’s look at the code for the JSP page.

Controller
Pagina JSP

WEB APP ARCHITECTURE WITH SPRING

Architettura Web App

As we have seen, the request arrives at the Servlet Dispatcher, which is responsible for searching for a controller that can return the desired resource. It also creates the view infrastructure, which, as we have seen, consists of JSP pages. All of these components are part of the Presentation Layer. Let us see what is meant by Domain Layer. In essence, the domain layer constitutes the tabular representation of the various entities. Let’s not forget the relationships, which will also need to be specified in this Layer.

Domain Layer

The persistence layer manages the data exchange between the application and the database.

Persistence Layer

The service layer is an intermediate layer; it is the junction between the various controllers and the persistence layer. In fact, it is a good idea for the controller not to access the persistence layer directly but through an intermediate layer that deals with business logic.

Service Layer

As we have already mentioned, it all starts with the request being taken over by the Presentation Layer, the model fits into the persistence layer because it is the mapping of all the tables in our relational database.

Schema Web App

DOWNLOAD ARTICLE CODE

ITEM CODE

Below is the video for importing into your project workspace.

THE JAVA LANGUAGE

THE JAVA LANGUAGE

LINKS TO PREVIOUS POSTS

SPRING FRAMEWORK