Author: European Xuan repair
图文 并 版 请 h 请 h版 如何 前 如何 商 如何 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商 商Business logic's processing, first let us first understand why the business logic and information show (Presentation), so we have the following benefits:
1. Reducing the impact of program changes: business logic and data show each other independent, not due to business logic changes, and the procedural code is affected, and vice versa. 2. Easy to maintain: Centralize business logic, once there is a modification, only need to modify one place. 3. Reuse: If the business logic is mixed with the information display layer program, such business logic can only serve a user interface (client), if the two are separated, we can easily expand the second user interface. 4. The designers and commercial logic designers are usually different from the design personnel of information, which makes the operations in specialization, quality and efficiency. In front of the PetStore business logic processing, we will first look at the invisible role in the PetStore. These invisible roles are ready for the server (RI), silently ready, to be properly timed to be commercial logic processing services in PetStore, so The author must introduce them first.
Please open PetStore_home (Note) /SRC /APPS/PETSTORE/SRC/Docroot/web-inf/web.xml, we can see:
! - Signon Attribute Listener ->
Encoding Filter its position in the program code Petstore_home / src / components / encodingfilter / src / com / sun / j2ee / blueprints / encodingfilter / web / EncodingFilter.java, it will re-read the web.xml (position Petstore_home / src / apps The parameters in /PETSTORE/Src/docroot/web-inf/web.xml determines the encoding method to set it in Request: Web.xml
The preset encoding is UTF-8, so we handle Chinese, must be processed in the program, and the Chinese characters must be transferred from Unicode to BIG5; to Tomcat3.3.x, Tomcat will pre- from OS Set the encoding method, so we don't have to handle itself; after tomcat4.0.x, the situation returns to Tomcat3.2.x, the author develops Web Application to encounter this situation, after three versions of Tomcat, program change Come over, do some white workers, and later, the author can use this filter, you don't need to convert Chinese characters from Unicode to BIG5 before depositing into the database. ComponentManager Listener Second Filter mainly depends on, close relationship with this topic, so that the process is smooth, so later explain. Let's look at the first Listener. Its main function is as a service link provider. When the user enters the system, the application sever will build a storage service connection container when the session is generated, and places it Entering the session and use after the subsequent program service is generated. DefaultComponentManager.java, source code Petstore_home / src / waf / src / controller / com / sun / j2ee / blueprints / waf / controller / webpublic void sessionCreated (HttpSessionEvent se) {HttpSession session = se.getSession (); // generates a service link container sl = ServiceLocator.getInstance (); // present Listener stored Session session.setAttribute (WebKeys.COMPONENT_MANAGER, this);} ServiceLacator.java, source code Petstore_home / src / components / servicelocator / src / com / sun / j2ee / Blueprints / ServiceLocator / Web, this category is full, you can learn more about programming skills, chasing seniors source code, in addition to how to understand how various functions are designed, program code decomposition (refactor), write style , Design skills, it is very important to gain! ServiceLacator basically is an EJB and JMS resource link service provider, and its service does not change due to the user, so it uses Static Writings to achieve this effect.