【正文】
能更好。 Struts 框架將執(zhí)行以下操作: ? 檢查 UserActionForm 是否存在;如果不存在,它將創(chuàng)建該類的一個實例。這使得人們更容易查看和理解它,尤其是 對于大型應(yīng)用程序而言。正如您所料 控制器使用配置文件以使您不必對這些值進(jìn)行硬編碼。 詳細(xì)分析 Struts 圖 3 示的是 包的一個最簡 UML 圖。就 Struts 而言,這是通過作為實際業(yè)務(wù)邏輯 “ 瘦 ” 包裝的 Action 類完成的。這個定義表示 Struts 是一個框架,而不是 一個庫,但 Struts 也包含了豐富的標(biāo)記庫和獨立于該框架工作的實用程序類。這種方法有幾個缺點: ? Java 程序員應(yīng)該開發(fā)服務(wù),而不是 HTML。當(dāng)更改模型時,視圖應(yīng)得到通知。 MVC 通過將問題分為三個類別來幫助解決單一模塊方法所遇到的某些問題: ? Model(模型 ) 模型包含應(yīng)用程序的核心功能。 如果您開發(fā)過大型 Web 應(yīng)用程序,您就理解 變化 這個詞的含義。s perfect.) The Error classes The UML diagram (Figure 4) also included ActionError and ActionErrors. ActionError encapsulates an individual error message. ActionErrors is a container of ActionError classes that the View can access using tags. ActionErrors is Struts way of keeping up with a list of errors. Figure 4:the relationship between Command (ActionServlet) and Model (Action) The ActionMapping class An ining event is normally in the form of an HTTP request, which the servlet Container turns into an HttpServletRequest. The Controller looks at the ining event and dispatches the request to an Action class. The determines what Action class the Controller calls. The configuration information is translated into a set of ActionMapping, which are put into container of ActionMappings. (If you have not noticed it, classes that end with s are containers) The ActionMapping contains the knowledge of how a specific event maps to specific 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. ActionMappings ActionMappings is a collection of ActionMapping objects. Struts pros ? Use of JSP tag mechanism The tag feature promotes reusable code and abstracts Java code from the JSP file. This feature allows nice integration into JSPbased development tools that allow authoring with tags. ? Tag library Why reinvent the wheel, or a tag library? If you cannot find something you need in the library, contribute. In addition, Struts provides a starting point if you are learning JSP tag technology. ? Open source You have all the advantages of open source, such as being able to see the code and having everyone else using the library reviewing the code. Many eyes make for great code review. ? Sample MVC implementation Struts offers some insight if you want to create your own MVC implementation. ? 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 problem is more plex and needs more management. Struts cons ? Youth Struts development is still in preliminary form. They are working toward releasing a version , but as with any version, it does not provide all the bells and whistles. ? Change The framework is undergoing a rapid amount of change. A great deal of change has occurred between Struts and . 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 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. ? Correct level of abstraction Does Struts provide the 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 Velocity 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 use a lot of Java. I saw this happen all the time in Microsoft ASP development. In ASP development, you were supposed to create COM objects and then write a little ASP script to glue it all together. Instead, the ASP developers would go crazy with ASP script. I would hear Why wait for a COM developer to create it when I can program it directly with VBScript? Struts helps limit the amount of Java code required in a JSP file via tag libraries. One such library is the Logic Tag, which manages conditional generation of output, but this does not prevent the UI developer from going nuts with Java code. Whatever type of framework you decide to use, you should understand the environment in which you are deploying and maintaining the f