[ Team LiB ] |
D.2 Presentation Tier Antipatterns
MistakeA single servlet performs duties of model, view, and controller, making the servlet large and difficult to maintain. Watch for It WhenServlets are large and complicated, servlets output HTML directly, or servlets are directly connected to databases or other external resources. SolutionRefactor into the MVC architecture. Separate all output generation into JSP pages or separate servlets. Separate calls to business data into reusable actions. Coordinate input processing, actions, and views with servlets.
MistakeA single JSP page performs duties of model, view, and controller, making the page large and difficult to maintain. Watch for It WhenJSP pages are large and complicated, JSP pages contain a large amount of embedded logic, JSP pages directly connect to databases or other external resources, or JSP pages contain lots of if/then statements. SolutionRefactor into the MVC architecture. Separate all output generation into JSP pages or separate servlets. Separate calls to business data into reusable actions. Coordinate input processing, actions, and views with servlets.
MistakeData with too short or long a lifespan is stored in the HTTP session, leading to excessive memory use and potential loss of important data. Watch for It WhenData stored in the session is only used in a single request, data stored in the session is used over a long period of time and should survive web server crashes. SolutionStore short-lived data in request scope. Store long-lived data in the business tier or other persistence mechanism. Make sure that data added to the session is removed when it is no longer relevant. |
[ Team LiB ] |