JWT Unit 5
JWT Unit 5
JWT Unit 5
Most modern web frameworks in JS follow the MVC design pattern encouraging developers to write clean, structured code. It allows
the developers to benefit all the benefits of modularity along with integrating a structure that accommodates multiple developers
working on the same project.
Model
View
● Handles the User Interface(UI). This component typically consists of the html, css, and static js files.
● The view component is used to attach and trigger user events but the event handling comes under the domain of the controller .
Controller
● The primary responsibility of a controller is to handle the events triggered by user input and also acts as a mediator between the view
and model.
● In other words, the controller contains client-side specific logic.
● The controller provides various functions based on events that can be triggered and then contacts the model for reading/updating
data and presents the new information to view component to be shown to the user.
Note: A router handles the HTTP requests or events towards the function in the controller that handles
them. Now let’s understand their working properly.
▹The router gets a HTTP request from browser and directs it towards the controller .
▹The controller than interacts with model to modify/read data from the database.
▹The new information is then passed onto the view which changes its state accordingly and sends it back to the
browser for the user to see.
Directory Structure
A common way to implement this architecture is to have the files for respective components in different folders. A
very basic directory structure for a project created as per MVC architecture might look something like this →
project-folder
│
├───controller
│ controller.js
│
├───model
│ db.js
│
└───view
│ home.html
│
└───index.js(entry-point to project)
Note: Obviously the file-names could be anything and the folder structure might differ a little too. In most cases,
there are more folders too containing static files, resource files, cache, routing, etc.
Conclusion
The MVC(Model-View-Controller) is a three-component architectural design each having its own role.
The Expression Language (EL) simplifies the accessibility of data stored in the Java Bean
component, and other objects like request, session, application etc.
There are many implicit objects, operators and reserve words in EL.
${ expression }
EL param example
In this example, we have created two files index.jsp and process.jsp. The index.jsp file
gets input from the user and sends the request to the process.jsp which in turn prints the
name of the user using EL.
index.jsp
<form action="process.jsp">
</form>
process.jsp
Welcome, ${ param.name }
EL sessionScope example
In this example, we printing the data stored in the session scope using EL. For this purpose, we have used
sessionScope object.
index.jsp
<h3>welcome to index page</h3>
<%
session.setAttribute("user","sonoo");
%>
<a href="process.jsp">visit</a>
process.jsp
Value is ${ sessionScope.user }
Using EL Operators and Accessing Database with JDBC
<%@ page import = "java.io.*,java.util.*,java.sql.*" %>
<%@ page import = "javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri ="http://java.sun.com/jsp/jstl/core" prefix = "c"%>
<%@ taglib uri ="http://java.sun.com/jsp/jstl/sql" prefix = "sql"%>
<html>
<head>
<title>SELECT Operation </title>
</head>
<body>
<sql:setDataSource var = "snapshot" driver = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://localhost/TEST"
user = "root" password = "pass123" />
</body>
</html>