Category: java
Introduction to spring expression language spel
Published on 30 Sep 2026
Explanation
In Servlet-JSP MVC, the Servlet acts as Controller, Java objects and services form the Model, and JSP acts as the View.
Code:
Browser | v Controller Servlet | v Service / Model | v Database | v Controller | v JSP View
Explanation
The servlet receives the request and calls the appropriate service or business logic.
Code:
@WebServlet("/students")
public class StudentServlet extends HttpServlet {
protected void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException {
List<Student> students = service.findAll();
req.setAttribute("students", students);
}
}
Explanation
The servlet stores model data in request attributes before forwarding the request to the JSP.
Code:
req.setAttribute("students", students);
req.getRequestDispatcher("students.jsp")
.forward(req, resp);
Explanation
The JSP uses EL and JSTL to display the data received from the controller.
Code:
<c:forEach var="student"
items="${students}">
<p>${student.name}</p>
</c:forEach>
Explanation
This separation keeps request handling, business logic, database operations, and presentation responsibilities separate.
Code:
Controller
↓
Service
↓
DAO
↓
Database
Controller
↓
JSP View
↓
HTML Response