`

表示层模式:Front Controller—前端控制器模式

阅读更多

Context
The presentation-tier request handling mechanism must control and coordinate
processing of each user across multiple requests. Such control mechanisms may be
managed in either a centralized or decentralized manner.
Problem
The system requires a centralized access point for presentation-tier request handling
to support the integration of system services, content retrieval, view management, and
navigation. When the user accesses the view directly without going through a centralized
mechanism, two problems may occur:
Each view is required to provide its own system services, often resulting in duplicate
code.
View navigation is left to the views. This may result in commingled view content and
view navigation.
Additionally, distributed control is more difficult to maintain, since changes will
often need to be made in numerous places.
Forces
Common system services processing completes per request. For example, the security
service completes authentication and authorization checks.
Logic that is best handled in one central location is instead replicated within
numerous views.
Decision points exist with respect to the retrieval and manipulation of data.
Multiple views are used to respond to similar business requests.
A centralized point of contact for handling a request may be useful, for example, to
control and log a user's progress through the site.
System services and view management logic are relatively sophisticated.
Solution
Use a controller as the initial point of contact for handling a request. The controller
manages the handling of the request, including invoking security services such as
authentication and authorization, delegating business processing, managing the choice of an
appropriate view, handling errors, and managing the selection of content creation strategies.
The controller provides a centralized entry point that controls and manages Web
request handling. By centralizing decision points and controls, the controller also helps
reduce the amount of Java code, called scriptlets, embedded in the JavaServer Pages (JSP)
page.
Centralizing control in the controller and reducing business logic in the view
promotes code reuse across requests. It is a preferable approach to the
alternative-embedding code in multiple views-because that approach may lead to a more
error-prone, reuse-by-copy- and-paste environment.
Typically, a controller coordinates with a dispatcher component. Dispatchers are
responsible for view management and navigation. Thus, a dispatcher chooses the next view
for the user and vectors control to the resource. Dispatchers may be encapsulated within the
controller directly or can be extracted into a separate component.
While the Front Controller pattern suggests centralizing the handling of all requests,
it does not limit the number of handlers in the system, as does a Singleton. An application
may use multiple controllers in a system, each mapping to a set of distinct services.

分享到:
评论

相关推荐

    33种JAVA设计模式DEMO

    创建型模式 ...前端控制器模式(Front Controller Pattern) 拦截过滤器模式(Intercepting Filter Pattern) 服务定位器模式(Service Locator Pattern) 传输对象模式(Transfer Object Pattern)

    J2EE核心模式.pdf

    8. 前端控制器模式(Front Controller):此模式将所有的请求处理都集中在一个控制器中处理,这个控制器负责拦截所有的请求并分发给相应的处理程序。在J2EE中,Servlet可以看作是前端控制器的一个实现。 9. 代理...

    java模式,设计模式,多种设计模式

    例如,`FrontController`(前端控制器)模式将Servlet代码的开发转化为了在图形用户界面下的开发。需要注意的是,J2EE设计模式解决了J2EE项目中最常见的问题。如果你遇到的问题非常特殊,很可能找不到相应的设计模式...

    J2EE核心模式

    8. **前端控制器(Front Controller)模式**:例如Servlet,负责处理所有来自客户端的请求,进行集中控制和调度。 9. **视图助手(View Helper)模式**:为JSP页面提供辅助对象,以保持视图与模型的分离,减少JSP...

    CakePHP框架指南

    它遵循了多种著名的设计模式,包括ActiveRecord(活动记录)、Association Data Mapping(关联数据映射)、Front Controller(前端控制器)和Model-View-Controller(模型-视图-控制器,简称MVC)模式。CakePHP旨在...

    设计模式.docx

    #### 前端控制器模式(Front Controller Pattern) 前端控制器模式定义了一个单一的控制器对象来接收所有的请求,然后分发给合适的处理程序。 #### 拦截过滤器模式(Intercepting Filter Pattern) 拦截过滤器...

    J2EE与设计模式--

    - **前端控制器(Front Controller)**:如JSF的FacesServlet,处理所有请求,统一应用逻辑。 4. **J2EE的并发与事务管理**: - **线程安全**:在多线程环境下,正确处理共享资源以避免数据不一致。 - **事务...

    J2EE核心模式(Core J2EE Patterns)

    5. **前端控制器(Front Controller)**:在Web应用中,前端控制器模式负责处理所有请求,调度业务逻辑,简化视图层的复杂性。 6. **模型-视图-控制器(Model-View-Controller, MVC)**:MVC模式是用于构建用户界面的...

    struts--MVC框架

    - **中央控制器(Front Controller)**:Struts框架中的`ActionServlet`作为前端控制器,负责接收所有请求,解析URL,并转发到对应的`Action`类进行处理。 - **Action**:业务控制器,执行具体的业务逻辑,返回一...

    structs的原理

    Struts2 作为 Web MVC 框架,采用了一种更新的 MVC 实现,即前端控制器(Front Controller)模式。在这个模式中,所有的 HTTP 请求都会先经过一个全局的 Servlet 分发器,即 Struts2 的 ActionServlet,它负责解析...

    struts1.0实例2

    框架提供了一组设计模式,如Front Controller(前端控制器)、Action和ActionForm,用于构建企业级Web应用程序。 2. **核心组件**: - **Front Controller(Struts Controller)**:Servlet `org.apache.struts....

    2023年Java Web应用开发中级复习课-理论题.pdf

    它负责接收前端控制器的请求,并将其分发给合适的处理器(Controller)。`DispatcherServlet`是SpringMVC的核心组件之一,用于初始化上下文和处理HTTP请求。当客户端发起请求时,请求会被`DispatcherServlet`拦截,...

    Patterns of Enterprise Application Architecture(PDF)

    5. **控制层**:书中讨论了前端控制器(Front Controller)模式,它集中处理所有请求,简化了系统架构。同时,书中也提到了拦截过滤器(Interceptor Filter)模式,用于在请求处理前进行预处理或后处理。 6. **企业...

    JavaEE环境下各类开发架构简介

    前端控制器模式,如Struts或Spring MVC,提供一个统一的入口点来处理所有用户请求,然后转发到适当的处理组件。 7. Inversion of Control (IoC) / Dependency Injection (DI) IoC和DI是控制反转和依赖注入的简称,...

    Killtest 免费提供 310-084 最新资料下载

    2. **Front Controller(前端控制器)**:该模式提供了一个中心控制点来处理所有的客户端请求,通过统一的入口点可以方便地添加通用处理逻辑,如日志记录,而无需在每个业务组件中重复相同的代码。 ### 知识点三:...

    WabacusBlank__公交查询系统软件源代码.zip

    6. **设计模式**:考虑到“jsp设计软件源码”,开发者可能采用了某种设计模式,如Model-View-Controller (MVC) 或 Front Controller,以提高代码的可读性和可维护性。 7. **部署与运行**:源代码需要在支持JSP和...

    SSH集成查询分页处理BaseDao

    - **Struts2**:负责前端控制器(Front Controller)和视图(View)的处理,通过Action类接收请求并调用Service层进行业务处理,然后返回结果到对应的JSP页面。 - **Spring**:提供依赖注入(DI)和面向切面编程...

    基于java的-40-13-医院电子病历管理系统-源码.zip

    `com.entity.view`、`com.model`和`com.service`、`com.service.impl`这些目录可能分别对应视图、模型和控制器层。 3. **实体类(Entity)**:`com.entity.view`下的类可能是用来表示数据库中的表或对象,用于封装...

Global site tag (gtag.js) - Google Analytics