計(jì)算機(jī)相關(guān)外文翻譯_第1頁(yè)
已閱讀1頁(yè),還剩35頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、<p>  外 文 翻 譯</p><p>  英文題目:Infrastructure for Automatic Dynamic Deployment Of J2EE Application in Distributed Environments & Struts——an open-source MVC implementation</p><p>  中文題

2、目:基于 J2EE 在分布式環(huán)境下的底層結(jié)構(gòu)的自動(dòng)動(dòng)態(tài)配置的應(yīng)用與Struts——MVC 的一種開(kāi)放源碼實(shí)現(xiàn)</p><p><b>  外文原文1</b></p><p>  Struts——an open-source MVC implementation</p><p>  Abstract: This article introduce

3、s Struts, a Model-View-Controller 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

4、system with Struts, you may get some ideas for your future servlets and JSP page implementation.</p><p>  Keywords: Struts; MVC; JSP</p><p>  1 Introduction</p><p>  Kids in grade s

5、chool put HTML pages on the Internet. 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 custo

6、mer, product flow, page layout, browser compatibility, 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 loo

7、king object interface than a user interface. </p><p>  If you have worked on a large-scale Web application, you understand the term change. Model-View-Controller (MVC) is a design pattern put together to hel

8、p control change. MVC decouples interface from business logic and data. Struts is an MVC implementation that uses Servlets 2.2 and JSP 1.1 tags, from the J2EE specifications, as part of the implementation. You may never

9、implement a system with Struts, but looking at Struts may give you some ideas on your future Servlets and JSP implementations.</p><p>  2 Model-View-Controller (MVC)</p><p>  JSP tags solved onl

10、y part of our problem. We still have issues with validation, flow control, and updating the state of the application. This is where MVC comes to the rescue. MVC helps resolve some of the issues with the single module app

11、roach by dividing the problem into three categories: </p><p>  Model The model contains the core of the application's functionality. The model encapsulates the state of the application. Sometimes the on

12、ly functionality it contains is state. It knows nothing about the view or controller. </p><p>  View The view provides the presentation of the model. It is the look of the application. The view can access t

13、he 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. </p><p>  Controller The controller

14、 reacts to the user input. It creates and sets the model. </p><p>  3 MVC Model 2</p><p>  The Web brought some unique challenges to software developers, most notably the stateless connection be

15、tween 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 re-query the server to discover modification to the state of the appl

16、ication.</p><p>  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 gene

17、rate HTML. There are several disadvantages to that approach: </p><p>  Java programmers should develop services, not HTML. </p><p>  Changes to layout would require changes to code. </p>

18、<p>  Customers of the service should be able to create pages to meet their specific needs. </p><p>  The page designer isn't able to have direct involvement in page development. </p><p&g

19、t;  HTML embedded into code is ugly. </p><p>  For the Web, the classical form of MVC needed to change. Figure 1 displays the Web adaptation of MVC, also commonly known as MVC Model 2 or MVC 2. </p>

20、<p>  Figure 1. MVC Model 2</p><p>  4 struts overview</p><p>  Struts is a set of cooperating classes, servlets, and JSP tags that make up a reusable MVC 2 design. This definition implies

21、 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 3 displays an overview of Struts. </p><

22、;p>  Struts overview :</p><p>  Client browser An HTTP request from the client browser creates an event. The Web container will respond with an HTTP response. </p><p>  Controller T

23、he Controller receives the request from the browser, and makes the decision where to send the request. With Struts, the Controller is a command design pattern implemented as a servlet. The struts-config.xml file configur

24、es the Controller. </p><p>  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 wrapp

25、er to the actual business logic. </p><p>  Model state The model represents the state of the application. The business objects update the application state. ActionForm bean represents the Model state at

26、 a session or request level, and not at a persistent level. The JSP file reads information from the ActionForm bean using JSP tags. </p><p>  View The view is simply a JSP file. There is no flow logic,

27、no business logic, and no model information -- just tags. Tags are one of the things that make Struts unique compared to other frameworks like Velocity. </p><p>  Figure 2. Struts overview</p><p&g

28、t;  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 flexib

29、ility and reuse.</p><p>  5 Struts details</p><p>  Displayed in Figure 3 is a stripped-down UML diagram of the org.apache.struts.action package. Figure 1 shows the minimal relationships among A

30、ctionServlet (Controller), ActionForm (Form State), and Action (Model Wrapper). </p><p>  Figure 3. UML diagram of the relationship of the Command (ActionServlet) to the Model (Action & ActionForm)</

31、p><p>  (1)The ActionServlet class </p><p>  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 config

32、uration information into a file and load the file at run time. Function pointer arrays were the good old days of structured programming in C. </p><p>  Life is better now that we have Java technology, XML, J

33、2EE, 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 hard-code the val

34、ues. Life changes, but stays the same. </p><p>  ActionServlet is the Command part of the MVC implementation and is the core of the Framework. ActionServlet (Command) creates and uses Action, an ActionForm,

35、and ActionForward. As mentioned earlier, the struts-config.xml file configures the Command. During the creation of the Web project, Action and ActionForm are extended to solve the specific problem space. The file struts-

36、config.xml instructs ActionServlet on how to use the extended classes. There are several advantages to this approach: </p><p>  The entire logical flow of the application is in a hierarchical text file. This

37、 makes it easier to view and understand, especially with large applications. </p><p>  The page designer does not have to wade through Java code to understand the flow of the application. </p><p&g

38、t;  The Java developer does not need to recompile code when making flow changes. </p><p>  Command functionality can be added by extending ActionServlet.</p><p> ?。?)The ActionForm class </p&

39、gt;<p>  ActionForm maintains the session state for the Web application. ActionForm is an abstract class that is sub-classed for each input form model. When I say input form model, I am saying ActionForm represent

40、s 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: </p><p>  Check to see if a UserActionFo

41、rm exists; if not, it will create an instance of the class. </p><p>  Struts will set the state of the UserActionForm using corresponding fields from the HttpServletRequest. No more dreadful request.getParam

42、eter() calls. For instance, the Struts framework will take fname from request stream and call UserActionForm.setFname(). </p><p>  The Struts framework updates the state of the UserActionForm before passing

43、it to the business wrapper UserAction. </p><p>  Before passing it to the Action class, Struts will also conduct form state validation by calling the validation() method on UserActionForm. Note: This is not

44、always wise to do. There might be ways of using UserActionForm in other pages or business objects, where the validation might be different. Validation of the state might be better in the UserAction class. </p><

45、;p>  The UserActionForm can be maintained at a session level. </p><p><b>  Notes: </b></p><p>  The struts-config.xml file controls which HTML form request maps to which ActionFor

46、m. </p><p>  Multiple requests can be mapped UserActionForm. </p><p>  UserActionForm can be mapped over multiple pages for things such as wizards. </p><p> ?。?)The Action class <

47、;/p><p>  The Action class is a wrapper around the business logic. The purpose of Action class is to translate the HttpServletRequest to the business logic. To use Action, subclass and overwrite the process() m

48、ethod. </p><p>  The ActionServlet (Command) passes the parameterized classes to ActionForm using the perform() method. Again, no more dreadful request.getParameter() calls. By the time the event gets here,

49、the input form data (or HTML form data) has already been translated out of the request stream and into an ActionForm class. </p><p>  Another way of thinking about Action class is as the Adapter design patte

50、rn. 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 incompatibility interface"

51、(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 <

52、;/p><p> ?。?)The Error classes </p><p>  The UML diagram (Figure 4) also included ActionError and ActionErrors. ActionError encapsulates an individual error message. ActionErrors is a container of

53、ActionError classes that the View can access using tags. ActionErrors is Struts way of keeping up with a list of errors.</p><p>  Figure 4. UML diagram of the relationship of the Command (ActionServlet) to

54、the Model (Action)(5)The ActionMapping class </p><p>  An incoming event is normally in the form of an HTTP request, which the servlet Container turns into an HttpServletRequest. The Controller looks at the

55、 incoming event and dispatches the request to an Action class. The struts-config.xml determines what Action class the Controller calls. The struts-config.xml configuration information is translated into a set of ActionMa

56、pping, which are put into container of ActionMappings. (If you have not noticed it, classes that end with s are containers)</p><p>  The ActionMapping contains the knowledge of how a specific event maps to s

57、pecific Actions. The ActionServlet (Command) passes the ActionMapping to the Action class via the perform() method. This allows Action to access the information to control flow.</p><p> ?。?)ActionMappings A

58、ctionMappings is a collection of ActionMapping objects.</p><p>  a)Struts pros </p><p>  Use of JSP tag mechanism The tag feature promotes reusable code and abstracts Java code from the JSP

59、 file. This feature allows nice integration into JSP-based development tools that allow authoring with tags. </p><p>  Tag library Why re-invent the wheel, or a tag library? If you cannot find something

60、 you need in the library, contribute. In addition, Struts provides a starting point if you are learning JSP tag technology. </p><p>  Open source You have all the advantages of open source, such as bein

61、g able to see the code and having everyone else using the library reviewing the code. Many eyes make for great code review. </p><p>  Sample MVC implementation Struts offers some insight if you want to

62、create your own MVC implementation. </p><p>  Manage the problem space Divide and conquer is a nice way of solving the problem and making the problem manageable. Of course, the sword cuts both ways. The

63、 problem is more complex and needs more management. </p><p>  b)Struts cons </p><p>  Youth Struts development is still in preliminary form. They are working toward releasing a version 1.0,

64、 but as with any 1.0 version, it does not provide all the bells and whistles. </p><p>  Change The framework is undergoing a rapid amount of change. A great deal of change has occurred between Struts 0.

65、5 and 1.0. You may want to download the most current Struts nightly distributions, to avoid deprecated methods. In the last 6 months, I have seen the Struts library grow from 90K to over 270K. I had to modify my examples

66、 several times because of changes in Struts, and I am not going to guarantee my examples will work with the version of Struts you download. </p><p>  Correct level of abstraction Does Struts provide the

67、 correct level of abstraction? What is the proper level of abstraction for the page designer? That is the $64K question. Should we allow a page designer access to Java code in page development? Some frameworks like Veloc

68、ity say no, and provide yet another language to learn for Web development. There is some validity to limiting Java code access in UI development. Most importantly, give a page designer a little bit of Java, and he will u

69、se </p><p>  Limited scope Struts is a Web-based MVC solution that is meant be implemented with HTML, JSP files, and servlets. </p><p>  J2EE application support Struts requires a servl

70、et container that supports JSP 1.1 and Servlet 2.2 specifications. This alone will not solve all your install issues, unless you are using Tomcat 3.2. I have had a great deal of problems installing the library with Netsc

71、ape iPlanet 6.0, which is supposedly the first J2EE-compliant application server. I recommend visiting the Struts User Mailing List archive (see Resources) when you run into problems. </p><p>  Complexity

72、 Separating the problem into parts introduces complexity. There is no question that some education will have to go on to understand Struts. With the constant changes occurring, this can be frustrating at times. Welcome

73、 to the Web. </p><p>  Where is... I could point out other issues, for instance, where are the client side validations, adaptable workflow, and dynamic strategy pattern for the controller? However, at t

74、his point, it is too easy to be a critic, and some of the issues are insignificant, or are reasonable for a 1.0 release. The way the Struts team goes at it, Struts might have these features by the time you read this arti

75、cle, or soon after. </p><p>  6 Future of Struts</p><p>  Things change rapidly in this new age of software development. In less than 5 years, I have seen things go from cgi/perl, to ISAPI/NSAPI

76、, to ASP with VB, and now Java and J2EE. Sun is working hard to adapt changes to the JSP/servlet architecture, just as they have in the past with the Java language and API. You can obtain drafts of the new JSP 1.2 and Se

77、rvlet 2.3 specifications from the Sun Web site. Additionally, a standard tag library for JSP files is appearing.</p><p><b>  外文翻譯2</b></p><p>  Struts——MVC 的一種開(kāi)放源碼實(shí)現(xiàn)</p><p

78、>  摘要:本文介紹 Struts,它是使用 servlet 和 JavaServer Pages 技術(shù)的一種 Model-View-Controller 實(shí)現(xiàn)。Struts 可幫助您控制 Web 項(xiàng)目中的變化并提高專(zhuān)業(yè)化水平。盡管您可能永遠(yuǎn)不會(huì)用 Struts 實(shí)現(xiàn)一個(gè)系統(tǒng),但您可以將其中的一些思想用于您以后的 servlet 和 JSP 網(wǎng)頁(yè)的實(shí)現(xiàn)中。</p><p>  關(guān)鍵字:Struts;MVC;

79、JSP</p><p><b>  1簡(jiǎn)介</b></p><p>  學(xué)生也可以在因特網(wǎng)上發(fā)布 HTML 網(wǎng)頁(yè)。但是,學(xué)生的網(wǎng)頁(yè)和專(zhuān)業(yè)開(kāi)發(fā)的網(wǎng)站有質(zhì)的區(qū)別。網(wǎng)頁(yè)設(shè)計(jì)人員(或者 HTML 開(kāi)發(fā)人員)必須理解顏色、用戶(hù)、生產(chǎn)流程、網(wǎng)頁(yè)布局、瀏覽器兼容性、圖像創(chuàng)建和 JavaScript 等等。設(shè)計(jì)漂亮的網(wǎng)站需要做大量的工作,大多數(shù) Java 開(kāi)發(fā)人員更注重創(chuàng)建優(yōu)美的對(duì)象

80、接口,而不是用戶(hù)界面。JavaServer Pages (JSP) 技術(shù)為網(wǎng)頁(yè)設(shè)計(jì)人員和 Java 開(kāi)發(fā)人員提供了一種聯(lián)系鈕帶。</p><p>  如果您開(kāi)發(fā)過(guò)大型 Web 應(yīng)用程序,您就理解 變化 這個(gè)詞的含義。“模型-視圖-控制器”(MVC) 就是用來(lái)幫助您控制變化的一種設(shè)計(jì)模式。MVC 減弱了業(yè)務(wù)邏輯接口和數(shù)據(jù)接口之間的耦合。Struts 是一種 MVC 實(shí)現(xiàn),它將 Servlet 2.2 和 JSP 1

81、.1 標(biāo)記(屬于 J2EE 規(guī)范)用作實(shí)現(xiàn)的一部分。盡管您可能永遠(yuǎn)不會(huì)用 Struts 實(shí)現(xiàn)一個(gè)系統(tǒng),但了解一下 Struts 或許使您能將其中的一些思想用于您以后的 Servlet 的 JSP 實(shí)現(xiàn)中。</p><p>  2 模型-視圖-控制器 (MVC)</p><p>  JSP 標(biāo)記只解決了部分問(wèn)題。我們還得處理驗(yàn)證、流程控制和更新應(yīng)用程序的狀態(tài)等問(wèn)題。這正是 MVC 發(fā)揮作用的

82、地方。MVC 通過(guò)將問(wèn)題分為三個(gè)類(lèi)別來(lái)幫助解決單一模塊方法所遇到的某些問(wèn)題:</p><p>  Model(模型):模型包含應(yīng)用程序的核心功能。模型封裝了應(yīng)用程序 的狀態(tài)。有時(shí)它包含的唯一功能就是狀態(tài)。它對(duì)視圖或控制器一無(wú)所知。 </p><p>  View(視圖):視圖提供模型的表示。它是應(yīng)用程序的 外觀。視圖可以訪問(wèn)模型的讀方法,但不能訪問(wèn)寫(xiě)方法。此外,它對(duì)控制器一

83、無(wú)所知。當(dāng)更改模型時(shí),視圖應(yīng)得到通知。 </p><p>  Controller(控制器):控制器對(duì)用戶(hù)的輸入作出反應(yīng)。它創(chuàng)建并設(shè)置模型。 </p><p>  3 MVC Model 2 </p><p>  Web 向軟件開(kāi)發(fā)人員提出了一些特有的挑戰(zhàn),最明顯的就是客戶(hù)機(jī)和服務(wù)器的無(wú)狀態(tài)連接。這種無(wú)狀態(tài)行為使得模型很難將更改通知視圖。在 Web 上,為了發(fā)現(xiàn)對(duì)

84、應(yīng)用程序狀態(tài)的修改,瀏覽器必須重新查詢(xún)服務(wù)器。</p><p>  另一個(gè)重大變化是實(shí)現(xiàn)視圖所用的技術(shù)與實(shí)現(xiàn)模型或控制器的技術(shù)不同。當(dāng)然,我們可以使用 Java(或者 PERL、C/C++ 或別的語(yǔ)言)代碼生成 HTML。這種方法有幾個(gè)缺點(diǎn):</p><p>  Java 程序員應(yīng)該開(kāi)發(fā)服務(wù),而不是 HTML。 </p><p>  更改布局時(shí)需要更改代碼。 <

85、;/p><p>  服務(wù)的用戶(hù)應(yīng)該能夠創(chuàng)建網(wǎng)頁(yè)來(lái)滿(mǎn)足它們的特定需要。 </p><p>  網(wǎng)頁(yè)設(shè)計(jì)人員不能直接參與網(wǎng)頁(yè)開(kāi)發(fā)。 </p><p>  嵌在代碼中的 HTML 很難看。 </p><p>  對(duì)于 Web,需要修改標(biāo)準(zhǔn)的 MVC 形式。圖 4 顯示了 MVC 的 Web 改寫(xiě)版,通常也稱(chēng)為 MVC Model 2 或 MVC 2。

86、</p><p>  圖 1. MVC Model 2 Struts,MVC 2 的一種實(shí)現(xiàn)</p><p>  4 Struts概覽</p><p>  Struts 是一組相互協(xié)作的類(lèi)、servlet 和 JSP 標(biāo)記,它們組成一個(gè)可重用的 MVC 2 設(shè)計(jì)。這個(gè)定義表示 Struts 是一個(gè)框架,而不是一個(gè)庫(kù),但 Struts 也包含了豐富的標(biāo)記庫(kù)和獨(dú)立于該

87、框架工作的實(shí)用程序類(lèi)。圖 5 顯示了 Struts 的一個(gè)概覽。Struts概覽:</p><p>  Client browser(客戶(hù)瀏覽器) 來(lái)自客戶(hù)瀏覽器的每個(gè) HTTP 請(qǐng)求創(chuàng)建一個(gè)事件。Web 容器將用一個(gè) HTTP 響應(yīng)作出響應(yīng)。 </p><p>  Controller(控制器) 控制器接收來(lái)自瀏覽器的請(qǐng)求,并決定將這個(gè)請(qǐng)求發(fā)往何處。就 Struts

88、而言,控制器是以 servlet 實(shí)現(xiàn)的一個(gè)命令設(shè)計(jì)模式。 struts-config.xml 文件配置控制器。 </p><p>  業(yè)務(wù)邏輯 業(yè)務(wù)邏輯更新模型的狀態(tài),并幫助控制應(yīng)用程序的流程。就 Struts 而言,這是通過(guò)作為實(shí)際業(yè)務(wù)邏輯“瘦”包裝的 Action 類(lèi)完成的。 </p><p>  Model(模型)的狀態(tài) 模型表示應(yīng)用程序的狀態(tài)。業(yè)務(wù)對(duì)象更新應(yīng)用程序

89、的狀態(tài)。ActionForm bean 在會(huì)話級(jí)或請(qǐng)求級(jí)表示模型的狀態(tài),而不是在持久級(jí)。JSP 文件使用 JSP 標(biāo)記讀取來(lái)自 ActionForm bean 的信息。 </p><p>  View(視圖) 視圖就是一個(gè) JSP 文件。其中沒(méi)有流程邏輯,沒(méi)有業(yè)務(wù)邏輯,也沒(méi)有模型信息 -- 只有標(biāo)記。標(biāo)記是使 Struts 有別于其他框架(如 Velocity)的因素之一。 </p>&

90、lt;p>  圖 2. Struts 概覽</p><p>  5 詳細(xì)分析 Struts</p><p>  圖 3 顯示的是 org.apache.struts.action 包的一個(gè)最簡(jiǎn) UML 圖。圖 6 顯示了 ActionServlet (Controller)、 ActionForm (Form State) 和 Action (Model Wrapper) 之間的最簡(jiǎn)

91、關(guān)系。 </p><p>  圖 3. Command與 Model 之間的關(guān)系的 UML 圖</p><p> ?。?)ActionServlet 類(lèi) </p><p>  您還記得函數(shù)映射的日子嗎?在那時(shí),您會(huì)將某些輸入事件映射到一個(gè)函數(shù)指針上。如果您對(duì)此比較熟悉,您會(huì)將配置信息放入一個(gè)文件,并在運(yùn)行時(shí)加載這個(gè)文件。函數(shù)指針數(shù)組曾經(jīng)是用 C 語(yǔ)言進(jìn)行結(jié)構(gòu)化編程

92、的很好方法。</p><p>  現(xiàn)在好多了,我們有了 Java 技術(shù)、XML、J2EE,等等。Struts 的控制器是將事件(事件通常是 HTTP post)映射到類(lèi)的一個(gè) servlet。正如您所料 -- 控制器使用配置文件以使您不必對(duì)這些值進(jìn)行硬編碼。時(shí)代變了,但方法依舊。</p><p>  ActionServlet 是該 MVC 實(shí)現(xiàn)的 Command 部分,它是這一框架的核心

93、。 ActionServlet (Command) 創(chuàng)建并使用 Action 、 ActionForm 和 ActionForward 。如前所述, struts-config.xml 文件配置該 Command。在創(chuàng)建 Web 項(xiàng)目時(shí),您將擴(kuò)展 Action 和 ActionForm 來(lái)解決特定的問(wèn)題。文件 struts-config.xml 指示 ActionServlet 如何使用這些擴(kuò)展的類(lèi)。這種方法有幾個(gè)優(yōu)點(diǎn): </p&

94、gt;<p>  應(yīng)用程序的整個(gè)邏輯流程都存儲(chǔ)在一個(gè)分層的文本文件中。這使得人們更容易查看和理解它,尤其是對(duì)于大型應(yīng)用程序而言。 </p><p>  網(wǎng)頁(yè)設(shè)計(jì)人員不必費(fèi)力地閱讀 Java 代碼來(lái)理解應(yīng)用程序的流程。 </p><p>  Java 開(kāi)發(fā)人員也不必在更改流程以后重新編譯代碼。 </p><p>  可以通過(guò)擴(kuò)展 ActionServle

95、t 來(lái)添加 Command 功能。 </p><p> ?。?)ActionForm 類(lèi) </p><p>  ActionForm 維護(hù) Web 應(yīng)用程序的會(huì)話狀態(tài)。 ActionForm 是一個(gè)抽象類(lèi),必須為每個(gè)輸入表單模型創(chuàng)建該類(lèi)的子類(lèi)。當(dāng)我說(shuō) 輸入表單模型 時(shí),是指 ActionForm 表示的是由 HTML 表單設(shè)置或更新的一般意義上的數(shù)據(jù)。例如,您可能有一個(gè)由 HTML 表單設(shè)

96、置的 UserActionForm 。Struts 框架將執(zhí)行以下操作: </p><p>  檢查 UserActionForm 是否存在;如果不存在,它將創(chuàng)建該類(lèi)的一個(gè)實(shí)例。 </p><p>  Struts 將使用 HttpServletRequest 中相應(yīng)的域設(shè)置 UserActionForm 的狀態(tài)。沒(méi)有太多討厭的 request.getParameter() 調(diào)用。例如,S

97、truts 框架將從請(qǐng)求流中提取 fname ,并調(diào)用 UserActionForm.setFname() 。 </p><p>  Struts 框架在將 UserActionForm 傳遞給業(yè)務(wù)包裝 UserAction 之前將更新它的狀態(tài)。 </p><p>  在將它傳遞給 Action 類(lèi)之前,Struts 還會(huì)對(duì) UserActionForm 調(diào)用 validation() 方

98、法進(jìn)行表單狀態(tài)驗(yàn)證。 注: 這并不總是明智之舉。別的網(wǎng)頁(yè)或業(yè)務(wù)可能使用 UserActionForm ,在這些地方,驗(yàn)證可能有所不同。在 UserAction 類(lèi)中進(jìn)行狀態(tài)驗(yàn)證可能更好。 </p><p>  可在會(huì)話級(jí)維護(hù) UserActionForm 。 </p><p><b>  注:</b></p><p>  struts-conf

99、ig.xml 文件控制 HTML 表單請(qǐng)求與 ActionForm 之間的映射關(guān)系。 </p><p>  可將多個(gè)請(qǐng)求映射到 UserActionForm 。 </p><p>  UserActionForm 可跨多頁(yè)進(jìn)行映射,以執(zhí)行諸如向?qū)е?lèi)的操作。 </p><p> ?。?)Action 類(lèi) </p><p>  Action 類(lèi)

100、是業(yè)務(wù)邏輯的一個(gè)包裝。 Action 類(lèi)的用途是將 HttpServletRequest 轉(zhuǎn)換為業(yè)務(wù)邏輯。要使用 Action ,請(qǐng)創(chuàng)建它的子類(lèi)并覆蓋 process() 方法。 </p><p>  ActionServlet (Command) 使用 perform() 方法將參數(shù)化的類(lèi)傳遞給 ActionForm 。仍然沒(méi)有太多討厭的 request.getParameter() 調(diào)用。當(dāng)事件進(jìn)展到這一步時(shí)

101、,輸入表單數(shù)據(jù)(或 HTML 表單數(shù)據(jù))已被從請(qǐng)求流中提取出來(lái)并轉(zhuǎn)移到 ActionForm 類(lèi)中。 </p><p>  注:擴(kuò)展 Action 類(lèi)時(shí)請(qǐng)注意簡(jiǎn)潔。 Action 類(lèi)應(yīng)該控制應(yīng)用程序的流程,而不應(yīng)該控制應(yīng)用程序的邏輯。通過(guò)將業(yè)務(wù)邏輯放在單獨(dú)的包或 EJB 中,我們就可以提供更大的靈活性和可重用性。 </p><p>  考慮 Action 類(lèi)的另一種方式是 Adapter

102、設(shè)計(jì)模式。 Action 的用途是“將類(lèi)的接口轉(zhuǎn)換為客戶(hù)機(jī)所需的另一個(gè)接口。Adapter 使類(lèi)能夠協(xié)同工作,如果沒(méi)有 Adapter,則這些類(lèi)會(huì)因?yàn)椴患嫒莸慕涌诙鵁o(wú)法協(xié)同工作?!保ㄕ?Gof 所著的 Design Patterns - Elements of Reusable OO Software )。本例中的客戶(hù)機(jī)是 ActionServlet ,它對(duì)我們的具體業(yè)務(wù)類(lèi)接口一無(wú)所知。因此,Struts 提供了它能夠理解的一個(gè)業(yè)務(wù)接

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 眾賞文庫(kù)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論