【正文】
s() method. The ActionServlet (Command) passes the parameterized classes to ActionForm using the perform() method. Again, no more dreadful () calls. By the time the event gets here, the input form data (or HTML form data) has already been translated out of the request stream and into an ActionForm class. Figure 4. MVC Model 2 Struts, an MVC 2 implementation Struts is a set of cooperating classes, servlets, and JSP tags that make up a reusable MVC 2 design. This definition implies that Struts is a framework, rather than a library, but Struts also contains an extensive tag library and utility classes that work independently of the framework. Figure 5 displays an overview of Struts. Figure 5. Struts overview Struts overview 大學(xué)畢業(yè)設(shè)計(jì)(論文) 第 6 頁(yè) ? Client browser An HTTP request from the client browser creates an event. The Web container will respond with an HTTP response. ? Controller The Controller receives the request from the browser, and makes the decision where to send the request. With Struts, the Controller is a mand design pattern implemented as a servlet. The file configures the Controller. ? Business logic The business logic updates the state of the model and helps control the flow of the application. With Struts this is done with an Action class as a thin wrapper to the actual business logic. ? Model state The model represents the state of the application. The business objects update the application state. ActionForm bean represents the Model state at a session or request level, and not at a persistent level. The JSP file reads information from the ActionForm bean using JSP tags. ? View The view is simply a JSP file. There is no flow logic, no business logic, and no model information just tags. Tags are one of the things that make Struts unique pared to other frameworks like Velocity. Note: Think thin when extending the Action class. The Action class should control the flow and not the logic of the application. By placing the business logic in a separate package or EJB, we allow flexibility and reuse. Another way of thinking about Action class is as the Adapter design pattern. The purpose of the Action is to Convert the interface of a class into another interface the clients expect. Adapter lets classes work together that couldn_t otherwise because of inpatibility interface (from Design Patterns Elements of Reusable OO Software by Gof). The client in this instance is the ActionServlet that knows nothing about our specific business class interface. Therefore, Struts provides a business interface it does understand, Action. By extending the Action, we make our business interface patible with Struts business interface. (An interesting observation is that Action is a class and not an interface. Action started as an interface and changed into a class over time. Nothing39。t able to have direct involvement in page development. ? HTML embedded into code is ugly. For the Web, the classical form of MVC needed to change. Figure 4 displays the Web adaptation of MVC, also monly known as MVC Model 2 or MVC 2. Struts details Displayed in Figure 6 is a strippeddown UML diagram of the package. Figure 6 shows the minimal relationships 大學(xué)畢業(yè)設(shè)計(jì)(論文) 第 3 頁(yè) among ActionServlet (Controller), ActionForm (Form State), and Action (Model Wrapper). Figure 6. UML diagram of the relationship of the Command (ActionServlet) to the Model (Action amp。大學(xué)畢業(yè)設(shè)計(jì)(論文) 第 1 頁(yè) 附錄 A 外文原文 (出處: Malcolm Davis. Strutsan opensource MVC implementation [J]. IBM Systems Journal, 2020,44(2):3337.) Struts—— an opensource MVC implementation Malcolm Davis This article introduces Struts, a ModelViewController implementation that uses servlets and JavaServer Pages (JSP) technology. Struts can help you control change in your Web project and promote specialization. Even if you never implement a system with Struts, you may get some ideas for your future servlets and JSP page implementation. Introduction Kids in grade school put HTML pages on the Inter. However, there is a monumental difference between a grade school page and a professionally developed Web site. The page designer (or HTML developer) must understand colors, the customer, product flow, page layout, browser patibility, image creation, JavaScript, and more. Putting a great looking site together takes a lot of work, and most Java developers are more interested in creating a great looking object interface than a user interface. JavaServer Pages (JSP) technology provides the glue between the page designer and the Java developer. If you have worked on a largescale Web application, you understand the term change. ModelViewController (MVC) is a design pattern put together to help control cha