【文章內(nèi)容簡(jiǎn)介】
control the flow and not the logic of the application. By placing the business logic in a separate package or EJB, we allow flexibility and reuse. Another way of thinking about Action class is as the Adapter design pattern. 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 inpatibility interface (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, Str uts provides a business interface it does understand, Action. By extending the Action, we make our business interface patible with Struts business interface. (An interesting observation is that Action is a class and not an interface. Action started as an interface and changed into a class over time. Nothing39。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. In