171
MVC in JSP
MVC stands for Model View and Controller. It is a design pattern that separates the business logic, presentation logic and data.
Controller acts as an interface between View and Model. Controller intercepts all the incoming requests.
Model represents the state of the application i.e. data. It can also have business logic.
View represents the presentaion i.e. UI(User Interface).
Advantage of MVC (Model 2) Architecture
- Navigation Control is centralized
- Easy to maintain the large application
If you new to MVC, please visit Model1 vs Model2 first.
MVC Example in JSP
In this example, we are using servlet as a controller, jsp as a view component, Java Bean class as a model.
In this example, we have created 5 pages:
- index.jsp a page that gets input from the user.
- ControllerServlet.java a servlet that acts as a controller.
- login-success.jsp and login-error.jsp files acts as view components.
- web.xml file for mapping the servlet.
File: index.jsp
File: ControllerServlet
File: LoginBean.java
File: login-success.jsp
File: login-error.jsp
File: web.xml
Output
Next TopicJstl