【正文】
require changes to code. ? Customers of the service should be able to create pages to meet their specific needs. ? The page designer isn39。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. 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 本科生畢業(yè)設(shè)計(jì)(論文)外文翻譯 3 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 6 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 6. UML diagram of the relationship of the Command (ActionServlet) to the Model (Action amp。 Struts 可幫助您控制 Web 項(xiàng)目中的變化并提高專業(yè)化水平。網(wǎng)頁(yè)設(shè)計(jì)人員(或者 HTML 開(kāi)發(fā)人員)必須理解顏色、用戶、生產(chǎn)流程、網(wǎng)頁(yè)布局、瀏覽器兼容性、圖像創(chuàng)建和 JavaScript 等等。 “模型 視圖 控制器 ”(MVC) 就是用來(lái)幫助您控制變化的一種設(shè)計(jì)模式。 模型 視圖 控制器 (MVC) JSP 標(biāo)記只解決了部分問(wèn)題。模型封裝了應(yīng)用程序的狀態(tài)。它是應(yīng)用程序的 外觀 。 ? Controller(控制器) 控制器對(duì)用戶的輸入作出反應(yīng)。在 Web 上,為了發(fā)現(xiàn)對(duì)應(yīng)用程序狀態(tài)的修改,瀏覽器必須重新查詢服務(wù)器。 ? 更改布局時(shí)需要更改代碼。 對(duì)于 Web,需要修改標(biāo)準(zhǔn)的 MVC 形式。圖 5 顯示了 Struts 的一個(gè)概覽。就 Struts 而言,控制器是以 servlet 實(shí)現(xiàn)的一個(gè)命令設(shè)計(jì)模式。 ? Model(模型)的狀態(tài) 模型表示應(yīng)用程序的狀態(tài)。 ? View(視圖) 視圖就是一個(gè) JSP 文件。圖 6 顯示了 ActionServlet (Controller)、 ActionForm (Form State) 和 Action (Model Wrapper) 之間的最簡(jiǎn)關(guān)系。函數(shù)指針數(shù)組曾經(jīng)是用 C 語(yǔ)言進(jìn)行結(jié)構(gòu)化編程的很好方法。時(shí)代變了,但方法依舊。在創(chuàng)建 Web 項(xiàng)目時(shí),您將擴(kuò)展 Action 和 ActionForm 來(lái)解決特定的問(wèn)題。 ? 網(wǎng)頁(yè)設(shè)計(jì)人員不必費(fèi)力地閱讀 Java 代碼來(lái)理解應(yīng)用程序的流程。 ActionForm 是一個(gè)抽象類,必須為每個(gè)輸入表單模型創(chuàng)建該類的子類。 ? Struts 將使用 HttpServletRequest 中相應(yīng)的域設(shè)置 UserActionForm 的狀態(tài)。 ? 在將它傳遞給 Action 類之前, Struts 還會(huì)對(duì) UserActionForm 調(diào)用 validation() 方法進(jìn)行表單狀態(tài)驗(yàn)證。 ? 可在會(huì)話級(jí)維護(hù) UserActionForm 。 Action 類 Action 類是業(yè)務(wù)邏輯的一個(gè)包裝。仍然沒(méi)有 太多討厭的 () 調(diào)用。通過(guò)將業(yè)務(wù)邏輯放在單獨(dú)的包或 EJB 中,我們就可以提供更大的靈活性和可重用性。 ”(摘自 Gof 所著的 Design Patterns Elements of Reusable OO Software)。(一個(gè)有趣的發(fā)現(xiàn)是, Action 是類而不是接 口)。 ActionError 封裝了單個(gè)錯(cuò)誤消息??刂破鞑榭摧斎胧录⒄?qǐng)求分派給某個(gè) Action 類。 ActionServlet (Command) 通過(guò) perform() 方法將 ActionMapping 傳遞給 Action 類。這個(gè)特性能很好地集成到基于 JSP 的開(kāi)發(fā)工具中,這些工具允許用標(biāo)記編寫代碼。許多人都可以進(jìn)行很好的代碼檢查。問(wèn)題越來(lái)越復(fù)雜,并且需要越來(lái)越多的管理。 Struts 與 Struts 相比變化極大。 本科生畢業(yè)設(shè)計(jì)(論文)外文翻譯 15 ? 正確的抽象級(jí)別 Struts 是否提供了正確的抽象級(jí)別?對(duì)于網(wǎng)頁(yè)設(shè)計(jì)人員而言,什么是正確的抽象級(jí)別呢?這是一個(gè)用 $64K 的文字才能解釋清楚的問(wèn)題。在 Microsoft ASP 的開(kāi)發(fā)中,我總是看到這樣的情況。 Logic Tag 就是這樣的一種庫(kù),它對(duì)有條件 地生成輸出進(jìn)行管理,但這并不能阻止 UI 開(kāi)發(fā)人員對(duì) Java 代碼的狂熱。 ? J2EE 應(yīng)用程序支持 Struts 需要支持 JSP 和 Servlet 規(guī)范的 servlet 容器。 ? 復(fù)雜性 在將問(wèn)題分為幾個(gè)部分的同時(shí)也引入了復(fù)雜性。 Struts 的前景 在這個(gè)軟件開(kāi)發(fā)的新時(shí)代,一切都變得很快。此外,一個(gè)標(biāo)準(zhǔn) JSP 標(biāo)記庫(kù)即將出現(xiàn)。 Sun 正在盡力將新的變化反映到 JSP/servlet 體系結(jié)構(gòu)中,正如他們對(duì) Java 語(yǔ)言和 API 所作的更改一樣。隨著變化的不斷加入,這有時(shí)會(huì)令人很沮喪。我用 Netscape iPla 安裝這個(gè)庫(kù)時(shí)遇到一大堆問(wèn)題,按理說(shuō)它是第一種符合 J2EE 的應(yīng)用程序服務(wù)器。當(dāng)然,這項(xiàng)任務(wù)真是說(shuō)起來(lái)容易做起來(lái)難。但是, ASP 開(kāi)發(fā)人員會(huì)瘋狂地使用 ASP 腳本。在 UI 開(kāi)發(fā)中限制訪問(wèn) Java 有一定的合理性。在過(guò)去的 6 個(gè)月中,我目睹 Struts 庫(kù)從 90K 增大到 270K 以 上。他們正在向著發(fā)行版本 而努力,但與任何 版本一樣,它不可能盡善盡美。 ? 管理問(wèn)題空間 分治是解決問(wèn)題并使問(wèn)題可管理的極好方法。此外,如果您正在學(xué)習(xí) JSP 標(biāo)記技術(shù),則 Struts 為您提供了一個(gè)起點(diǎn)。 ActionMappings ActionMappings 是 ActionMapping 對(duì)象的一個(gè)集合。 配置信息被轉(zhuǎn)換為一組 ActionMapping ,而后者又被放入 ActionMappings 容器中。 ActionError 是 Struts 保持錯(cuò)誤列表的方式。真是金無(wú)足赤。因此, Struts 提供了它能夠理解的一個(gè)業(yè)務(wù)接口,即 Action 。 Action 的用途是 “將類的接口轉(zhuǎn)換為客戶機(jī)所需的另一個(gè)接口。 注:擴(kuò)展 Action 類時(shí)請(qǐng)注意簡(jiǎn)潔。要使用 Action ,請(qǐng)創(chuàng)建它的子類并覆蓋 process() 方法。 ? 可將多個(gè)請(qǐng)求映射到 UserActionForm 。別的網(wǎng)頁(yè)或業(yè)務(wù)可能使用 Use