1. What is MVC?
MVC Pattern stands for Model-View-Controller Pattern. This pattern is used to separate application’s concerns.
Model: Handles data and business logic.
View: Presents the data to the user whenever asked for.
Controller: Entertains user requests and fetch necessary resources.
2. Example:
The whole program is as the picture show
First we create some jsp pages including index,jsp, login.jsp, signUp.jsp, about.jsp, notFound.jsp, codes are as following:
// index,jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Home Page</title>
</head>
<body>
<!-- 完成简单的MVC控制 -->
This is the home page where program start<br/>
<!-- 使用Servlet作为controller来控制JSP页面的访问-->
<a href="<%=request.getContextPath() %>/T?page=login">login</a><br/>
<a href="<%=request.getContextPath() %>/T?page=about">about</a><br/>
<a href="<%=request.getContextPath() %>/T?page=signU