Web Application Development Course

Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

WEB APPLICATION DEVELOPMENT

COURSE OBJECTIVES:

1. To study the insights of the Web architecture


2. To gain knowledge in client and server model in web application
3. To be trained on MVC development
4. To understand the designing applications over web using Spring Framework.
5. To get acquainted with applications over the web using ‘Django’ Framework.

CONTENT
 Web Basics and Overview: Introduction to Internet, World Wide Web, Web Browsers,
URL , MVC Framework and Design Pattern, Types of PHP MVC framework.
 Servlets: Introduction to Servlets, Benefits of Servlets, use as controller in MVC.
 Spring Framework Overview, Spring Web MVC Overview, Controllers,
 Introduction to Django, Django architecture, Django Models and Database
Backends, Developing Web Application using Django
UNIT - I

Web Basics and Overview: Introduction to Internet, World Wide Web, Web Browsers,

URL , HTTP.

PHP: Declaring Variables, Data types, Operators, Control structures, Functions. MVC

Framework and Design Pattern, Types of PHP MVC framework.

Introduction to Internet:-A global computer network providing a variety of information and


communication facilities, consisting of interconnected networks using standardized
communication protocols. "the guide is also available on the Internet"

The Internet is the global system of interconnected computer networks that use the Internet
protocol suite (TCP/IP) to link devices worldwide. It is a network of networks that consists of
private, public, academic, business, and government networks of local to global scope, linked by
a broad array of electronic, wireless, and optical networking technologies. The Internet carries a
vast range of information resources and services.

History of Internet
This marvelous tool has quite a history that holds its roots in the cold war scenario. A
need was realized to connect the top universities of the United States so that they can share all
the research data without having too much of a time lag. This attempt was a result of Advanced
Research Projects Agency (ARPA) which was formed at the end of 1950s just after the Russians
had climbed the space era with the launch of Sputnik. After the ARPA got success in 1969, it
didn’t take the experts long to understand that how much potential can this interconnection tool
have. In 1971 Ray Tomlinson made a system to send electronic mail. This was a big step in the
making as this opened gateways for remote computer accessing i.e. telnet.

During all this time, rigorous paper work was being done in all the elite research
institutions. From giving every computer an address to setting out the rules, everything was
getting penned down. 1973 saw the preparations for the vital TCP/IP and Ethernet services. At
the end of 1970s, Usenet groups had surfaced up. By the time the 80s had started, IBM came up
with its PC based on Intel 8088 processor which was widely used by students and universities for
it solved the purpose of easy computing. By 1982, the Defense Agencies made the TCP/IP
compulsory and the term ―internet‖ was coined. The domain name services arrived in the year
1984 which is also the time around which various internet based marked their debut. A worm, or
a rust the computers, attacked in 1988 and disabled over 10% of the computer systems all over
the world. While most of the researchers regarded it as an opportunity to enhance computing as it
was still in its juvenile phase, quite a number of computer companies became interested in
dissecting the cores of the malware which resulted to the formation Computer Emergency
Rescue Team (CERT). Soon after the world got over with the computer worm, World Wide Web
came into existence. Discovered by Tim Berners-Lee, World Wide Web was seen as a service to
connect documents in websites using hyperlinks.
World Wide Web
The World Wide Web (abbreviated WWW or the Web) is an information space where
documents and other web resources are identified by Uniform Resource Locators (URLs),
interlinked by hypertext links, and can be accessed via the Internet. English scientist Tim
Berners-Lee invented the World Wide Web in 1989. He wrote the first web browser computer
program in 1990 while employed at CERN in Switzerland. The Web browser was released
outside CERN in 1991, first to other research institutions starting in January 1991 and to the
general public on the Internet in August 1991.
The World Wide Web has been central to the development of the Information Age and is
the primary tool billions of people use to interact on the Internet. Web pages are primarily text
documents formatted and annotated with Hypertext Markup Language (HTML). In addition to
formatted text, web pages may contain images, video, audio, and software components that are
rendered in the user's web browser as coherent pages of multimedia content.
Embedded hyperlinks permit users to navigate between web pages. Multiple web pages
with a common theme, a common domain name, or both, make up a website. Website content
can largely be provided by the publisher, or interactively where users contribute content or the
content depends upon the users or their actions. Websites may be mostly informative, primarily
for entertainment, or largely for commercial, governmental, or non-governmental organizational
purposes

WWW is another example of client/server computing. Each time a link is followed, the client is
requesting a document (or graphic or sound file) from a server (also called a Web server) that's
part of the World Wide Web that "serves" up the document. The server uses a protocol called
HTTP or Hyper Text Transport Protocol. The standard for creating hypertext documents for the
WWW is Hyper Text Markup Language or HTML. HTML essentially codes plain text
documents so they can be viewed on the Web.

Browsers:
WWW Clients, or "Browser": The program you use to access the WWW is known as a
browser because it "browses" the WWW and requests these hypertext documents. Browsers can
be graphical, allows to see and hear the graphics and audio;
text-only browsers (i.e., those with no sound or graphics capability) are also available. All of
these programs understand http and other Internet protocols such as FTP, gopher, mail, and news,
making the WWW a kind of "one stop shopping" for Internet users.
Uniform Resource Locators, or URLs: A Uniform Resource Locator, or URL is the address of a
document found on the WWW. Browser interprets the information in the URL in order to connect
to the proper Internet server and to retrieve your desired document. Each time a click on a
hyperlink in a WWW document instructs browser to find the URL that's embedded within the
hyperlink.
The elements in a URL: Protocol://server's address/filename

Hypertext protocol: http://www.aucegypt.edu


File Transfer Protocol: ftp://ftp.dartmouth.edu
Telnet Protocol: telnet://pac.carl.org
News Protocol: news:alt.rock-n-roll.stones
What are Domains? Domains divide World Wide Web sites into categories based on the nature
of their owner, and they form part of a site's address, or uniform resource locator (URL).
Common top-level domains are:

.com—commercial enterprises .mil—military site

org—organization site (non-profits, int—organizations established by


etc.) international treaty

.net—network .biz—commercial and personal

.edu—educational site (universities, .info—commercial and personal


schools, etc.)

.gov—government organizations .name—personal sites


Additional three-letter, four-letter, and longer top-level domains are frequently added.
Each country linked to the Web has a two-letter top-level domain, for example .fr is France, .ie is
Ireland.
MIME (Multi-Purpose Internet Mail Extensions):- MIME is an extension of the original
Internet e-mail protocol that lets people use the protocol to exchange different kinds of
data files on the Internet: audio, video, images, application programs, and other kinds, as well as the ASCII text
handled in the original protocol, the Simple Mail Transport Protocol (SMTP). In 1991, Nathan Borenstein of
Bellcore proposed to the IETF that SMTP be extended so that Internet (but mainly Web) clients and servers could
recognize and handle other kinds of data than ASCII text. As a result, new file types were added to "mail" as a
supported Internet Protocol file type.

Servers insert the MIME header at the beginning of any Web transmission. Clients use this header to
select an appropriate "player" application for the type of data the header indicates. Some of these players are built
into the Web client or browser (for example, all browsers come with GIF and JPEG image players as well as the
ability to handle HTML files); other players may need to be downloaded.
New MIME data types are registered with the Internet Assigned Numbers Authority (IANA).
MIME is specified in detail in Internet Request for Comments 1521 and 1522, which amend the original
mail protocol specification, RFC 821 (the Simple Mail Transport Protocol) and the ASCII messaging header,
RFC 822.

Hypertext Transport Protocol:


HTTP means HyperText Transfer Protocol. HTTP is the underlying protocol used by the World Wide Web and
this protocol defines how messages are formatted and transmitted, and what actions Web servers and browsers
should take in response to various commands.
For example, when you enter a URL in your browser, this actually sends an HTTP command to the Web server
directing it to fetch and transmit the requested Web page. The other main standard that controls how the World
Wide Web works is HTML, which covers how Web pages are formatted and displayed.
HTTP is called a stateless protocol because each command is executed independently, without any knowledge of
the commands that came before it. This is the main reason that it is difficult to implement Web sites that react
intelligently to user input.

HTTPS: A similar abbreviation, HTTPS means Hyper Text Transfer Protocol Secure. Basically, it is the secure
version of HTTP. Communications between the browser and website are encrypted by Transport Layer Security
(TLS), or its predecessor, Secure Sockets Layer (SSL).

Web App Vs. Website - Can There Be A difference?

You're perfectly suited to ask that question. It's the first thought that comes to mind and it's a good thing
too. The distinction between a website and a web-based app is a bit unclear.

This is the main difference. A website may be a static website that only provides information, and it may not
be able to verify the input.

On the other hand, a Web application is a dynamic web-based application that responds to inputs from
users and allows users to complete specific tasks via the internet.

Also, in short, any site that has the client-side component that permits users to complete tasks can be
referred to as a web app.
Web applications are created to carry out specific functions that aid users in solving a particular problem. But
websites aren't designed solely to provide details.

Web Apps vs. Mobile Apps

Web applications can be used with the web on any computer as well as mobile. The real issue is mobile web
applications as opposed to. native apps for mobile devices.

Native apps are specifically designed for platforms and are designed specifically to work on Android as well
as iOS devices. They must be downloaded from an app store, and installed within your phone. While they
can provide a personal experience, they're costly to create and take up space on devices, they are also tied to
the device.

However, Web apps can be readily used on any device since they can be accessed via an internet browser.
Furthermore, they do not consume storage space on devices in addition creating a web-based application is
less expensive and feasible.

Benefits in Web Application Development

As a developer, mastering web-based applications opens many possibilities for you. Every company today
requires an effective and affordable solution for software applications that allows them to reach out to users
on every device, whether desktop or mobile, and on every platform.

Web application development is platform-independent, which means that businesses don't have to create
separate apps for iOS and Android, this can increase the price.

Web application technology has developed tremendously in the past several years. They have made Web
applications as immersive and personal as native applications.

Even companies that have top-rated native apps require the same high-quality web applications since they
can't afford to lose their web and desktop customers. Facebook, Instagram, WhatsApp all have web
applications that are compatible that integrate with native applications.

Learning how to build an application for the web puts you at the top of the market that includes the top
companies that require an extensive online presence.
The types used in Web Applications

Let's begin by understanding the various types of web-based apps there are. We can categorize them

according to what they are and the way they appear.

Generally, web applications are divided into five categories, each with distinct characteristics and distinctive
features. Let's examine the five types of web apps.

1. Static Web Applications

So-called because of their structure and inflexibility static web applications are more of a collection of static
websites that show the same information to each user. They are created with HTML along with CSS and do
not offer interactivity.

Because the pages of static web application development are created on the server's end There is no space
in the application for customization.

Pages for static web apps can be a challenge to modify or update. You'll need to perform an entire page
reload for any changes to be visible.

With all the above are static web application development ever being carried out currently?

Certain companies that need a basic web page that conveys vital business information that requires no input
can benefit from a static application. For instance, personal portfolios and business contact pages, and
company information pages could utilize this type of web application development to achieve immediate
and cost-effective results.

2. Applications for dynamic web

Dynamic web applications like the name imply they are interactive and require both client and server-side
programming. For instance, if you enter details into a web application and get different results, then that's an
active website.

If you can make a search, set up an account for yourself, leave comments or engage in other dynamic ways,
then you're using a web application.
Pages in dynamic web applications don't follow a set sequence of displays but are formed by input on the
server or client-side. They use an application called a content management system, or CMS, which alters the
contents of the app.

A variety of programming languages, like PHP and ASP, create an online application. The apps need websites,
databases, and servers.

Although technically, all applications that aren't static websites are dynamic, a few more broad categories
comprise the remaining portion of this list of applications.

3. Ecommerce apps

If you plan to sell or purchase things online, you'll need at a minimum an online application that can take
orders and accept payment. This kind of app is known as an e-commerce app.

This raises the technical difficulty of creating an online application to a new stage. From keeping a database
up-to-date of merchandise to managing offers, orders, and transactions, web applications involve more
programming.

The creation of an experience that is similar to native app experiences is also crucial for web applications for
e-commerce so that customers can have a seamless experience, regardless of the device they're on.

4. Portal Web Apps

A portal web application is an application on the web that permits users to log in to secure areas from the
home page. Consider credit card payments for example. It could be an online shopping site or bill payment
site, and when it's time to pick an account with a credit card to pay for a transaction, then you're asked to
sign in to the web portal of the credit card company's application to complete the transaction. This is an
example of web-based portals.

5. Content Management System or CMS Web App

CMS, also known as a content management system, CMS can allow even non-technical users to create and
edit content online. From simple blogs to a larger website and more,CMS allows users to keep these
resources up-to-date with the most current information.
Making an app that users who are not technical require specific technologies that should be reserved for
professional web application developers.

6. Progressive Web Apps

Progressive web applications (PWAs) aren't simply the term used to describe web-based applications. There,
in actuality the most significant leap forward in web-based applications development.

A PerfectionGeeks utilizes the most up-to-date and most efficient web frameworks and technology for
application development to provide you with an app that blends the best of native mobile and web
applications.

These applications behave as an accessible website that you can save to your home screen with no download
and then access at any time, you'd like in just a single click.

Furthermore, a progressive app makes use of a wide range of web technologies, plugins, and APIs, giving
you an experience comparable to native apps that are top of the line however it is much easier and faster to
build than native applications.

A study has shown that the average app loses 20 percent of its users each step from identifying the app until
they begin using it. The reason for this is that users have to find a native app from the store and download it.

Once downloaded, they can get connected and then start using it.

A PerfectionGeeks On the contrary functions exactly like a web page. Users can begin using it the moment
they are aware of it and skip the need to download and then onboard. But once they've added it to the
display of their home screen - - which only takes just a few seconds and they will be able to receive push
notifications as well as personalized messages to improve engagement.

How the Web Works : Client-Server Model & the Structure of


a Web Application
The Client-Server Model
This idea of a client and server communicating over a network is called the “Client-Server”
model. It’s what makes viewing websites (like this one) and interacting with web
applications (like Gmail) possible.
The Client-Server model is really just a way to describe the give-and-take relationship
between the client and server in a web application — just like you might use “boyfriend”
and “girlfriend” to describe your personal relationships. It’s the details of how information
passes from one end to the other where the picture gets complicated.
A Basic Web App Configuration
There are hundreds of ways to configure a web application. That said, most of them follow
the same basic structure: a client, a server, and a database.
The client
The client is what the user interacts with. So “client-side” code is responsible for most of
what a user actually sees. This includes:
Defining the structure of the web page
Setting the look and feel of the web page
Implementing a mechanism for responding to user interactions (clicking buttons, entering
text, etc.)
Structure: The layout and content of your webpage are defined by HTML (usually HTML 5
when it comes to web apps these days, but that’s another story.)
HTML stands for Hyper Text Markup Language. It allows you to describe the basic
physical structure of a document using HTML tags. Each HTML tag describes a specific
element on the document.
For example:
The content within the “<h1>” tag describes the heading.
The content within the “<p>” tag describes a paragraph.
The content within the “<button>” tag describes a button.
And so on…
A web browser uses these HTML tags to determine how to display the document.
Look and Feel: To define the look and feel of a webpage, web developers use CSS, which
stands for Cascading Style Sheets. CSS is a language that that lets you describe how the
elements defined in your HTML should be styled, allowing changes in font, color, layout,
simple animations, and other superficial elements.
You could set styles for the above HTML page like this:
User interactions: Lastly, JavaScript comes into the picture to handle user interactions.
For example, if you want to do something when a user clicks your button, you might do
something like this:

Some user interactions, like the one above, can be handled without ever having to reach out
to your server — hence the term “client-side JavaScript.” Other interactions require that you
send the requests to your server to handle.
For example, if a user posts a comment on a thread, you might want to store that comment
in your database to keep all the riff-raff organized in one place. So, you’d send the request
to the server with the new comment and user ID, and the server would listen for those
requests and process them accordingly.
We’ll go much more in depth into HTTP request-response in the next part of this series.
The server
The server in a web application is what listens to requests coming in from the client. When
you set up an HTTP server, you set it up to listen to a port number. A port number is always
associated with the IP address of a computer.
You can think of ports as separate channels on each computer that you can use to perform
different tasks: one port could be surfing www.facebook.com while another fetches your
email. This is possible because each of the applications (the web browser and the email
client) use different port numbers.
Once you’ve set up an HTTP server to listen to a specific port, the server waits for client
requests coming to that specific port, performs any actions stated by the request, and sends
any requested data via an HTTP response.
The database
Databases are the basements of web architecture — most of us are scared to go down there,
but they’re critical to a solid foundation. A database is a place to store information so that it
can easily be accessed, managed, and updated.
If you’re building a social media site, for example, you might use a database to store
information about your users, posts, and comments. When a visitor requests a page, the data
inserted into the page comes from the site’s database, allowing for the real-time user
interactions we take for granted on sites like Facebook or apps like Gmail.
That’s all folks! (Well, sorta…)
It’s as simple as that. We just walked through all the basic functionality of a web application.
How to Scale a Simple Web Application
The above configuration is great for simple applications. But as an application grows, a
single server won’t have the power to handle thousands — if not millions — of concurrent
requests from visitors.
In order to scale to meet these high volumes, one thing we can do is distribute the incoming
traffic across a group of back-end servers.
This is where things gets interesting. You have multiple servers, each with its own IP
address. So how does the Domain Name Server (DNS) know which instance of your
application to send your traffic to?
The simple answer is that it doesn’t. The way to manage all these separate instances of your
application is through something called a load balancer.
The load balancer acts as a traffic cop that routes client requests across the servers in the
fastest and most efficient manner possible.
Since you can’t broadcast the IP addresses of all your server instances, you create a Virtual
IP address, which is the address you publicly broadcast to clients. This Virtual IP address
points to your load balancer. So when there’s a DNS lookup for your site, it’ll point to the
load balancer. Then the load balancer jumps in to distribute traffic to your various back-end
servers in real-time.
You might be wondering how the load balancer knows which server to send traffic to. The
answer: algorithms.
One popular algorithm, Round Robin, involves evenly distributing incoming requests across
the your server farm (all your available servers). You would typically choose this approach
if all of your servers have similar processing speed and memory.
With another algorithm, Least Connections, the next request is sent to the server with the
least number of active connections.
There are many more algorithms you can implement, depending on your needs.
So now the flow looks like this:
Services
Ok, so we solved our traffic problem by creating pools of servers and a load balancer to
manage them. Works great, right?
…But just replicating a bunch of servers could still lead to problems as your application
grows. As you add more functionality to your application, you’d have to keep maintaining
the same monolithic server while it continues to grow. To solve this, we need a way to
decouple the functionality of the server.
This is where the idea of a service comes in. A service is just another server, except that it
only interacts with other servers, as opposed to a traditional web server which interacts with
clients.
Each service has a self-contained unit of functionality, such as authorizing users or
providing a search functionality. Services allow you to break up your single web server into
multiple services that each performs a discrete functionality.
The main benefit of breaking up a single server into many services is that it allows you to
scale the services completely independently.
The other advantage here is that it allows teams within a company to work independently on
a particular service, rather than having 10s, 100s or even 1000s of engineers working on one
monolithic server, which quickly becomes a project management nightmare.

Quick note here: this concept of load balancers and pools of back-end servers and services
gets very challenging as you scale to add more and more servers to your application. It’s
gets especially tricky with things like session persistence — such as how to handle sending
multiple requests from a client to the same server for the duration of a session — and how to
deploy your load balancing solution. We’ll leave those advanced topics out for this post.
Content Delivery Networks
All of the above works great for scaling traffic, but your application is still centralized in
one location. When your users start visiting your site from other sides of the country — or
the other side of the world — they might encounter longer load times because of the
increased distance between the client and server. After all, we’re talking about the “World
Wide Web” — not the “local neighborhood web.” :)

A popular tactic to solve this is using a Content Delivery Network (CDN). A CDN is a large
distributed system of “proxy” servers deployed across many data centers. A proxy server is
just a server that acts as an intermediary between a client and a server.
Companies with large amounts of distributed traffic can choose to pay CDN companies to
deliver their content to their end-users using the CDN’s servers. An example of a CDN is
Akamai. Akamai has thousands of servers located in strategic geographical locations around
the world.
Let’s compare how a website works with and without a CDN.
As we talked about in Section 1, for a typical website, the domain name of a URL is
translated to the IP address of the host’s server.
However, if a customer uses Akamai, the domain name of the URL is translated to the IP
address of an edge server owned by Akamai. Akamai then delivers the web content to the
customer’s users, without it ever having to touch the customer’s servers.
Akamai is able to do this by storing copies of frequently used elements like HTML, CSS,
software downloads, and media objects from customers’ servers.
The main goal is to bring your website’s content closer to your user. If the content doesn’t
have to travel as far to get to the user, it means lower latency, which in turn reduces the load
time.

MVC Framework
The Model-View-Controller (MVC) is an architectural pattern that separates an application
into three main logical components: the model, the view, and the controller. Each of these
components are built to handle specific development aspects of an application. MVC is one
of the most frequently used industry-standard web development framework to create scalable
and extensible projects.
MVC Components
Following are the components of MVC −

Model
The Model component corresponds to all the data-related logic that the user works with. This
can represent either the data that is being transferred between the View and Controller
components or any other business logic-related data. For example, a Customer object will
retrieve the customer information from the database, manipulate it and update it data back to
the database or use it to render data.
View
The View component is used for all the UI logic of the application. For example, the
Customer view will include all the UI components such as text boxes, dropdowns, etc. that
the final user interacts with.
Controller
Controllers act as an interface between Model and View components to process all the
business logic and incoming requests, manipulate data using the Model component and
interact with the Views to render the final output. For example, the Customer controller will
handle all the interactions and inputs from the Customer View and update the database using
the Customer Model. The same controller will be used to view the Customer data.

Types of PHP MVC framework


Selecting the best PHP framework is a challenge. You don’t have to write your own
framework to benefit from the advantages of MVC. You should only attempt to create your
own MVC related application design for understanding how MVC frameworks work.

Once you are comfortable with the way MVC frameworks work, you should move on to the
mature and already tested frameworks.
The table below briefly describes some of the popular php frameworks and the
features that each framework offers.

Framework Description

It is one of the most popular PHP MVC frameworks. It’s lightweight and a
CodeIgniter short l rich set of libraries that help build websites and applications rapidly.
Users with limited programming can also use it. CodeIgniter powered
applications include
It’s a Hierarchical Model View Controller HMVC secure and lightweight
Kohana framework. components for developing applications rapidly. Companies
that use Kohana include;

CakePHP It is modeled after Ruby on rails. It’s known for concepts such as software
design patt configuration, ActiveRecord etc. CakePHP powered applications
include;
It is a powerful framework that is;

 Secure, reliable, fast, and scalable


 Supports Web 2.0 and creation of web services.

Zend It features APIs from vendors like Amazon, Google, Flickr, Yahoo etc. It’s
ideal for de applications. Zend powered applications include;

 Pimcore CMS,
 DotKernel.

Companies using the Zend framework include;

 BBC
 Cisco
 Webex
 Offers.com
INTRODUCTION TO SERVLETS
Servlets:
• Servlets are server side programs that run on a Web or Application server and act as a
middle layer between a requests coming from a Web browser and databases or
applications on the server.
• Using Servlets, you can collect input from users through web page forms, present records
from a database or another source, and create web pages dynamically.
• Servlets don’t fork new process for each request, instead a new thread is created.
• Servlets are loaded and ready for each request.
• The same servlet can handle many requests simultaneously.

The advantages of Servlet are as follows:

1. Better performance: because it creates a thread for each request, not process.
2. Portability: because it uses Java language.
3. Robust: JVM manages Servlets, so we don't need to worry about the memory leak, garbage
collection, etc.
4. Secure: because it uses java language
Servlet API
Servlet API consists of two important packages that encapsulates all the important classes
and interface, namely :
1. javax.servlet
2. javax.servlet.http

1. javax.servlet
Interfaces
1. Servlet – Declares life cycle methods for a servlet.
2. ServletConfig – To get initialization parameters
3. ServletContext- To log events and access information
4. ServletRequest- To read data from a client request
5. ServletResponse – To write data from client response
Classes
1. GenericServlet – Implements Servlet and ServletConfig
2. ServletInputStream – Provides an input stream for reading client requests.
3. ServletOutputStream - Provides an output stream for writing
responses to a client.
4. ServletException – Indicates servlet error occurred.
5. UnavailableException - Indicates servlet is unavailable

Servlet Interface

 Servlet interface provides common behaviour to all the servlets.


 Servlet interface needs to be implemented for creating any servlet (either directly or
indirectly).
 It provides 3 life cycle methods that are used to initialize the servlet, to service the
requests, and to destroy the servlet and 2 non-life cycle methods.

Spring Framework Overview


Spring makes it easy to create Java enterprise applications. It provides everything you need to
embrace the Java language in an enterprise environment, with support for Groovy and Kotlin
as alternative languages on the JVM, and with the flexibility to create many kinds of
architectures depending on an application’s needs. As of Spring Framework 5.1, Spring
requires JDK 8+ (Java SE 8+) and provides out-of-the-box support for JDK 11 LTS. Java SE
8 update 60 is suggested as the minimum patch release for Java 8, but it is generally
recommended to use a recent patch release.

Spring supports a wide range of application scenarios. In a large enterprise, applications often
exist for a long time and have to run on a JDK and application server whose upgrade cycle is
beyond developer control. Others may run as a single jar with the server embedded, possibly
in a cloud environment. Yet others may be standalone applications (such as batch or
integration workloads) that do not need a server.

Spring is open source. It has a large and active community that provides continuous feedback
based on a diverse range of real-world use cases. This has helped Spring to successfully
evolve over a very long time.

1. What We Mean by "Spring"


The term "Spring" means different things in different contexts. It can be used to refer to the
Spring Framework project itself, which is where it all started. Over time, other Spring
projects have been built on top of the Spring Framework. Most often, when people say
"Spring", they mean the entire family of projects. This reference documentation focuses on
the foundation: the Spring Framework itself.

The Spring Framework is divided into modules. Applications can choose which modules they
need. At the heart are the modules of the core container, including a configuration model and
a dependency injection mechanism. Beyond that, the Spring Framework provides
foundational support for different application architectures, including messaging,
transactional data and persistence, and web. It also includes the Servlet-based Spring MVC
web framework and, in parallel, the Spring WebFlux reactive web framework.

A note about modules: Spring’s framework jars allow for deployment to JDK 9’s module
path ("Jigsaw"). For use in Jigsaw-enabled applications, the Spring Framework 5 jars come
with "Automatic-Module-Name" manifest entries which define stable language-level module
names ("spring.core", "spring.context", etc.) independent from jar artifact names (the jars
follow the same naming pattern with "-" instead of ".", e.g. "spring-core" and "spring-
context"). Of course, Spring’s framework jars keep working fine on the classpath on both
JDK 8 and 9+.
2. History of Spring and the Spring Framework
Spring came into being in 2003 as a response to the complexity of the
early J2EE specifications. While some consider Java EE and Spring to be in competition,
Spring is, in fact, complementary to Java EE. The Spring programming model does not
embrace the Java EE platform specification; rather, it integrates with carefully selected
individual specifications from the EE umbrella:

 Servlet API (JSR 340)

 WebSocket API (JSR 356)

 Concurrency Utilities (JSR 236)

 JSON Binding API (JSR 367)

 Bean Validation (JSR 303)

 JPA (JSR 338)

 JMS (JSR 914)

 as well as JTA/JCA setups for transaction coordination, if necessary.

The Spring Framework also supports the Dependency Injection (JSR 330) and Common
Annotations (JSR 250) specifications, which application developers may choose to use
instead of the Spring-specific mechanisms provided by the Spring Framework.

As of Spring Framework 5.0, Spring requires the Java EE 7 level (e.g. Servlet 3.1+, JPA 2.1+)
as a minimum - while at the same time providing out-of-the-box integration with newer APIs
at the Java EE 8 level (e.g. Servlet 4.0, JSON Binding API) when encountered at runtime.
This keeps Spring fully compatible with e.g. Tomcat 8 and 9, WebSphere 9, and JBoss EAP 7.

Over time, the role of Java EE in application development has evolved. In the early days of
Java EE and Spring, applications were created to be deployed to an application server. Today,
with the help of Spring Boot, applications are created in a devops- and cloud-friendly way,
with the Servlet container embedded and trivial to change. As of Spring Framework 5, a
WebFlux application does not even use the Servlet API directly and can run on servers (such
as Netty) that are not Servlet containers.

Spring continues to innovate and to evolve. Beyond the Spring Framework, there are other
projects, such as Spring Boot, Spring Security, Spring Data, Spring Cloud, Spring Batch,
among others. It’s important to remember that each project has its own source code repository,
issue tracker, and release cadence. See spring.io/projects for the complete list of Spring
projects.
3. Design Philosophy
When you learn about a framework, it’s important to know not only what it does but what
principles it follows. Here are the guiding principles of the Spring Framework:

 Provide choice at every level. Spring lets you defer design decisions as late as
possible. For example, you can switch persistence providers through configuration
without changing your code. The same is true for many other infrastructure concerns
and integration with third-party APIs.

 Accommodate diverse perspectives. Spring embraces flexibility and is not


opinionated about how things should be done. It supports a wide range of application
needs with different perspectives.

 Maintain strong backward compatibility. Spring’s evolution has been carefully


managed to force few breaking changes between versions. Spring supports a carefully
chosen range of JDK versions and third-party libraries to facilitate maintenance of
applications and libraries that depend on Spring.

 Care about API design. The Spring team puts a lot of thought and time into making
APIs that are intuitive and that hold up across many versions and many years.

 Set high standards for code quality. The Spring Framework puts a strong emphasis on
meaningful, current, and accurate javadoc. It is one of very few projects that can
claim clean code structure with no circular dependencies between packages.

Spring - MVC Framework


The Spring Web MVC framework provides a model-view-controller architecture and ready
components that can be used to develop flexible and loosely coupled web applications. The
MVC pattern results in separating the different aspects of the application (input logic,
business logic, and UI logic), while providing a loose coupling between these elements.

 The Model encapsulates the application data and in general, they will consist of POJO.
 The View is responsible for rendering the model data and in general, it
generates HTML output that the client's browser can interpret.
 The Controller is responsible for processing User Requests and Building Appropriate
Model and passes it to the view for rendering.

The Dispatcher Servlet


The Spring Web model-view-controller (MVC) framework is designed around a
DispatcherServlet that handles all the HTTP requests and responses. The request processing
workflow of the Spring Web MVC DispatcherServlet is shown in the following illustration.
Following is the sequence of events corresponding to an incoming HTTP request to DispatcherServlet

 After receiving an HTTP request, DispatcherServlet consults the HandlerMapping to call the
appropriate Controller.
 The Controller takes the request and calls the appropriate service methods based on
used GET or POST method. The service method will set model data based on defined business
logic and returns view name to the DispatcherServlet.
 The DispatcherServlet will take help from ViewResolver to pick up the defined view for the
request.
 Once view is finalized, The DispatcherServlet passes the model data to the view, which is
finally rendered, on the browsers.
All the above-mentioned components, i.e. HandlerMapping, Controller and ViewResolver are parts
of WebApplicationContext, which is an extension of the plain ApplicationContext with some extra
features necessary for web applications.
Introduction to Django
Django is a Python-based web framework that allows you to quickly create efficient web applications.
It is also called batteries included framework because Django provides built-in features for everything
including Django Admin Interface, default database – SQLlite3, etc. When you’re building a website,
you always need a similar set of components: a way to handle user authentication (signing up, signing
in, signing out), a management panel for your website, forms, a way to upload files, etc. Django gives
you ready-made components to use and that too for rapid development.
Why Django Framework ?
 Excellent documentation and high scalability.
 Used by Top MNCs and Companies, such as Instagram, Disqus, Spotify, Youtube, Bitbucket,
Dropbox, etc. and the list is never-ending.
 Easiest Framework to learn, rapid development and Batteries fully included.
 The last but not least reason to learn Django is Python, Python has huge library and features such
as Web Scrapping, Machine Learning, Image Processing, Scientific Computing, etc. One can
integrate it all this with web application and do lots and lots of advance stuff.

Django Architecture – 3 Major Components of MVC Pattern


In the previous article, we learned the unique features of Django. Now, we will discuss about Django
architecture based on MVC pattern. We will be understanding the MVC pattern in more detail.
Django MVC architecture solves lots of problems which were there in the traditional approach for web
development.
We will understand the components of the MVC pattern that are Model, Views, and Controller in detail.
1. Model
The Model is the part of the web-app which acts as a mediator between the website interface and the
database. In technical terms, it is the object which implements the logic for the application’s data
domain. There are times when the application may only take data in a particular dataset, and directly
send it to the view (UI component) without needing any database then the dataset is considered as a
model.
Although today if we want any kind of website we need to have some sort of database as we must be
requiring some user input even if we are creating a simple blog site.
The Model is the component which contains Business Logic in Django architecture.
For example:
When you sign up on any website you are actually sending information to the controller which then
transfers it to the models which in turn applies business logic on it and stores in the database.

Explore how to create a project in Django.

2. View
This component contains the UI logic in the Django architecture.
View is actually the User Interface of the web-application and contains the parts like HTML, CSS and
other frontend technologies. Generally, this UI creates from the Models component, i.e., the content
comes from the Models component.
For example:
When you click on any link or interact with the website components, the new webpages that
website generates is actually the specific views that stores and generates when we are interacting
with the specific components.
3. Controller
The controller as the name suggests is the main control component. What that means is, the
controller handles the user interaction and selects a view according to the model.
The main task of the controller is to select a view component according to the user interaction and
also applying the model component.
This architecture has lots of advantages and that’s why Django is also based on this architecture. It
takes the same model to an advanced level.
For example:
When we combine the two previous examples, then we can very clearly see that the component
which is actually selecting different views and transferring the data to the model’s component is the
controller.
Django Models and Database
Backends Databases
Django officially supports the following databases:

 PostgreSQL
 MariaDB
 MySQL
 Oracle
 SQLite

PostgreSQL notes
Django supports PostgreSQL 10 and higher. psycopg2 2.8.4 or higher is required, though the
latest release is recommended.
PostgreSQL connection settings
See HOST for details.
To connect using a service name from the connection service file and a password from the
password file, you must specify them in the OPTIONS part of your database configuration in
DATABASES:
settings.py¶
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'OPTIONS': {
'service': 'my_service',
'passfile': '.my_pgpass',
},
}
}
MariaDB notes

Django supports MariaDB 10.2 and higher.

To use MariaDB, use the MySQL backend, which is shared between the two. See the MySQL
notes for more details.

MySQL notes
Version
support

Django supports MySQL 5.7 and higher.


Django’s inspectdb feature uses the information_schema database, which contains detailed
data on all database schemas.Django expects the database to support Unicode (UTF-8
encoding) and delegates to it the task of enforcing transactions and referential integrity. It is
important to be aware of the fact that the two latter ones aren’t actually enforced by MySQL
when using the MyISAM storage engine, see the next section.

MySQL notes
Version
support

Django supports MySQL 5.7 and higher.Django’s inspectdb feature uses the
information_schema database, which contains detailed data on all database schemas.Django
expects the database to support Unicode (UTF-8 encoding) and delegates to it the task of
enforcing transactions and referential integrity. It is important to be aware of the fact that the
two latter ones aren’t actually enforced by MySQL when using the MyISAM storage engine,
see the next section.

You might also like