【正文】
on 可訪問(wèn)用 于控制流程的信息。 ActionErrors 是 ActionError 類(lèi)的容器, View 可以使用標(biāo)記訪問(wèn)這些類(lèi)。本例中的客戶機(jī)是 ActionServlet ,它對(duì)我們的具體業(yè)務(wù)類(lèi)接口一無(wú)所知。當(dāng)事件進(jìn)展到這一步時(shí),輸入表單數(shù)據(jù)(或 HTML 表單數(shù)據(jù))已被從請(qǐng)求流中提取出來(lái)并轉(zhuǎn)移到 ActionForm 類(lèi)中。 注: ? 文件控制 HTML 表單請(qǐng)求與 ActionForm 之間的映射關(guān)系。沒(méi)有太多討厭的 () 調(diào)用。 ? Java 開(kāi)發(fā)人員也不必在更改流程以后重新編譯代碼。 ActionServlet 是該 MVC 實(shí)現(xiàn)的 Command 部分,它是這一框架的核心。 圖 3. Command (ActionServlet) 與 Model (Action amp。業(yè)務(wù)對(duì)象更新應(yīng)用程序的狀態(tài)。 圖 2. Struts 概覽 Struts 概覽 ? Client browser(客戶瀏覽器) 來(lái)自客戶瀏覽器的每個(gè) HTTP 請(qǐng)求創(chuàng)建一個(gè)事件。 ? 服務(wù)的用戶應(yīng)該能夠創(chuàng)建網(wǎng)頁(yè)來(lái)滿足它們的特定需要。它創(chuàng)建并設(shè)置模型。有時(shí)它包含的唯一功能就是狀態(tài)。 MVC 減弱了業(yè)務(wù)邏輯接口和數(shù)據(jù)接口之間的耦合。盡管您可能永遠(yuǎn)不會(huì)用 Struts 實(shí)現(xiàn)一個(gè)系統(tǒng),但您可以將其中的一些思想用于您以后的 servlet 和 JSP 網(wǎng)頁(yè)的實(shí)現(xiàn)中。s functionality. The model encapsulates the state of the application. Sometimes the only functionality it contains is state. It knows nothing about the view or controller. ? View The view provides the presentation of the model. It is the look of the application. The view can access the model getters, but it has no knowledge of the setters. In addition, it knows nothing about the controller. The view should be notified when changes to the model occur. ? Controller The controller reacts to the user input. It creates and sets the model. MVC Model 2 The Web brought some unique challenges to software developers, most notably the stateless connection between the client and the server. This stateless behavior made it difficult for the model to notify the view of changes. On the Web, the browser has to requery the server to discover modification to the state of the application. Another noticeable change is that the view uses different technology for implementation than the model or controller. Of course, we could use Java (or PERL, C/C++ or what ever) code to generate HTML. There are several disadvantages to that approach: ? Java programmers should develop services, not HTML. ? Changes to layout would require changes to code. ? Customers of the service should be able to create pages to meet their specific needs. ? The page designer isn39。網(wǎng)頁(yè)設(shè)計(jì)人員(或者 HTML 開(kāi)發(fā)人員)必須理解顏色、用戶、生產(chǎn)流程、網(wǎng)頁(yè)布局、瀏覽器兼容性、圖像創(chuàng)建和 JavaScript 等等。 模型 視圖 控制器 (MVC) JSP 標(biāo)記只解決了部分問(wèn)題。它是應(yīng)用程序的 外觀 。在 Web 上,為了發(fā)現(xiàn)對(duì)應(yīng)用程序狀態(tài)的修改,瀏覽器必須重新查詢服務(wù)器。 對(duì)于 Web,需要修改標(biāo)準(zhǔn)的 MVC 形式。就 Struts 而言,控制器是以 servlet 實(shí)現(xiàn)的一個(gè)命令設(shè)計(jì)模式。 ? View(視圖) 視圖就是一個(gè) JSP 文件。函數(shù)指針數(shù)組曾經(jīng)是用 C 語(yǔ)言進(jìn)行結(jié)構(gòu)化編程的很好方法。在創(chuàng)建 Web 項(xiàng)目時(shí),您將擴(kuò)展 Action 和 ActionForm 來(lái)解決特定的問(wèn)題。 ActionForm 是一個(gè)抽象類(lèi),必須為每個(gè)輸入表單模型創(chuàng)建該類(lèi)的子類(lèi)。 ? 在將它傳遞給 Action 類(lèi)之前, Struts 還會(huì)對(duì) UserActionForm 調(diào)用 validation() 方法進(jìn)行表單狀態(tài)驗(yàn)證。 Action 類(lèi) Action 類(lèi)是業(yè)務(wù)邏輯的一個(gè)包裝。通過(guò)將業(yè)務(wù)邏輯放在單獨(dú)的包或 EJB 中,我們就可以提供更大的靈活性和可重用性。(一個(gè)有趣 的發(fā)現(xiàn)是, Action 是類(lèi)而不是接口)??刂破鞑榭摧斎胧录⒄?qǐng)求分派給某個(gè) Action 類(lèi)。這個(gè)特性能很好地集成到基于 JSP 的開(kāi)發(fā)工具中,這些工具允許用標(biāo)記編寫(xiě)代碼。問(wèn)題越來(lái)越復(fù)雜,并且需要越來(lái)越多的管理。 ? 正確的抽象級(jí)別 Struts 是否提供了正確的抽象級(jí)別?對(duì)于網(wǎng)頁(yè)設(shè)計(jì)人員而言,什么是正確的抽象級(jí)別呢?這是一個(gè)用 $64K 的文字才能解釋清楚的問(wèn)題。 Logic Tag 就是這樣的一種庫(kù),它對(duì)有條件地生成輸出進(jìn)行管理,但這并不能阻止 UI 開(kāi)發(fā)人員對(duì) Java 代碼的狂熱。 ? 復(fù)雜性 在將問(wèn)題分為幾個(gè)部分的同時(shí)也引入了復(fù)雜性。此外,一個(gè)標(biāo)準(zhǔn) JSP 標(biāo)記庫(kù)即將出現(xiàn) 。 Struts 的前景 在這個(gè)軟件開(kāi)發(fā)的新時(shí)代,一切都變得很快。 ? J2EE 應(yīng)用程序支持 Struts 需要支持 JSP 和 Servlet 規(guī)范的 servlet 容器。在 Microsoft ASP 的開(kāi)發(fā)中,我總是看到這樣的情況。 Struts 與 Struts 相比變化極大。許多人都可以進(jìn)行很好的代碼檢查。 ActionServlet (Command) 通過(guò) perform() 方法將 ActionMapping 傳遞給 Action 類(lèi)。 ActionError 封裝了單個(gè)錯(cuò)誤消息。 ” (摘自 Gof 所著的 Design Patterns Elements of Reusable OO Software )。仍然沒(méi)有太多討厭的 () 調(diào)用。 ? 可在會(huì)話級(jí)維護(hù) UserActionForm 。 ? Struts 將使用 HttpServletRequest 中相應(yīng)的域設(shè)置 UserActionForm 的狀態(tài)。 ? 網(wǎng)頁(yè)設(shè)計(jì)人員不必費(fèi)力地閱讀 Java 代碼來(lái)理解應(yīng)用程序的流程。時(shí)代變了,但方法依舊。圖 3 顯示了 ActionServlet (Controller)、 ActionForm (Form State) 和 Action (Model Wrapper) 之間的最簡(jiǎn)關(guān)系。 ? Model(模型)的狀態(tài) 模型表示應(yīng)用程序的狀態(tài)。圖 2 顯示了 Struts 的一個(gè)概覽。 ? 更改布局時(shí)需要更改代碼。 ? Controller(控制器) 控制器對(duì)用戶的輸入作出反應(yīng)。模型封裝了應(yīng)用程序的狀態(tài)。 “ 模型 視圖 控制器 ”(MVC) 就是用來(lái)幫助您控制變化的一種設(shè)計(jì)模式。 Struts 可幫助您控制 Web 項(xiàng)目中的變化并提高專(zhuān)業(yè)化水平。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 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