【正文】
velopment. ? HTML embedded into code is ugly. For the Web, the classical form of MVC needed to change. Figure 1 displays the Web adaptation of MVC, also monly known as MVC Model 2 or MVC 2. Figure 1. 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 2 displays an overview of Struts. Figure 2. Struts view Struts overview ? 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. Struts details Displayed in Figure 3 is a strippeddown UML diagram of the package. Figure 6 shows the minimal relationships among ActionServlet (Controller), ActionForm (Form State), and Action (Model Wrapper). Figure 3:the relationship between ActionServlet (Controller)、 ActionForm (Form State) and Action (Model Wrapper) The ActionServlet class Do you remember the days of function mappings? You would map some input event to a pointer to a function. If you where slick, you would place the configuration information into a file and load the file at run time. Function pointer arrays were the good old days of structured programming in C. Life is better now that we have Java technology, XML, J2EE, and all that. The Struts Controller is a servlet that maps events (an event generally being an HTTP post) to classes. And guess what the Controller uses a configuration file so you don_t have to hardcode the values. Life changes, but stays the same. ActionServlet is the Command part of the MVC implementation and is the core of the Framework. ActionServlet (Command) creates and uses Action, an ActionForm, and ActionForward. As mentioned earlier, the file configures the Command. During the creation of the Web project, Action and ActionForm are extended to solve the specific problem space. The file instructs ActionServlet on how to use the extended classes. There are several advantages to this approach: ? The entire logical flow of the application is in a hierarchical text file. This makes it easier to view and understand, especially with large applications. ? The page designer does not have to wade through Java code to understand the flow of the application. ? The Java developer does not need to repile code when making flow changes. Command functionality can be added by extending ActionServlet. The ActionForm class ActionForm maintains the session state for the Web application. ActionForm is an abstract class that is subclassed for each input form model. When I say input form model, I am saying ActionForm represents a general concept of data that is set or updated by a HTML form. For instance, you may have a UserActionForm that is set by an HTML Form. The Struts framework will: ? Check to see if a UserActionForm exists。 外 文 翻 譯 學(xué) 院: 信息科學(xué)與工程學(xué)院 專 業(yè): 計(jì)算機(jī)科學(xué)與技術(shù) 學(xué)生姓名: 宋清云 學(xué)生班級(jí): 計(jì)算機(jī) 0801 班 學(xué)生學(xué)號(hào): 080405017 指導(dǎo)教師: 崔文成 指導(dǎo)教師評(píng)語(yǔ) 指導(dǎo)教師簽名: 年 月 日 Struts—— an opensource MVC implementation This article introduces Struts, a ModelViewController implementation that uses servlets and JavaServer Pages (JSP) tech