The front-end controller processes all requests from users. All users' requests must pass the front-end controller, and only the front-end controller is reordered by the front-end controller to access the corresponding resources only after obtaining the controller authentication. This is a way of security control. In fact, under the J2EE architecture, the linkage of various resources is implemented by XML. All files for all web layer applications must be packaged into a WAR file, and web files are usually some JSP files, and there are also some servlets and javabean. And JSP tags. In a simple web application, you can implement direct access to business methods, or even background database resources, etc. in JSP files. But as an extensible and scalable application, there is a lot of inconvenience. This will have a more detailed argument in MVC mode analysis and application. It is to focus here that the front-end controller mode is implemented in the application. Let's take a look at Front Control class diagram [I]:
Any mode has a context environment (Context), in the front-end controller mode application environment can be distributed, although the controller is only one, it may be a plurality of controller distributed to handle different Control requirements. This distributed control mechanism is implemented by the web configuration file Web.xml. Of course, you can also centralize all requests, and judge the distribution request in a centralized environment. A chain structure can be implemented. This is actually the Chain of Responsibility mode of GOF, further mapped into the J2EE mode directory, strictly speaking in front of us should take filter mode, so that the front end verification can be better processed, but the process of such steps It is easy to cause low efficiency. It takes time because it is necessary to judge the chain. As mentioned earlier, the request is described by the configuration file. Here is the web configuration file in an example program I develop:
1
2
3
4
5 servlet>
6
7
8
9 servlet-mapping>
10
11
12
13 servlet>
14
15
16
17 servlet-mapping>
18 web-app>
When there is a client request, the container must read the configuration file to determine the user's access to the resource, and distribute some type of user to the corresponding controller. The 16 line of application is to specify that all files under Test under the sub-directory of the context (developed) must be handed over to a servlet called Loginfront. Map this servlet into a JSP file in 11 lines (you know that JSP is in nature is servlet). At the login.jsp file, it is actually just a user interface. He handed the obtained request to the servlet called Logincheck (there should be a corresponding description in the configuration) - a typical view (JSP implementation) - controller (servlet implementation) Pattern (