Whats in Struts 2 ?

If you have programmed with Struts 1, this post provides a brief introduction of what to expect in Struts 2.

• Instead of a servlet controller like the ActionServlet class in Struts 1, Struts 2 uses a filter to perform the same task.

• There are no action forms in Struts 2. In Struts 1, an HTML form maps to an ActionForm instance. You can then access this action form from your action class and use it to populate a data transfer object. In Struts 2, an HTML form maps directly to a POJO. You don't need to create a data transfer object and, since there are no action forms, maintenance is easier and you deal with fewer classes.

• Now, if you don't have action forms, how do you programmatically validate user input in Struts 2? By writing the validation logic in the action class.

• Struts 1 comes with several tag libraries that provides custom tags to be used in JSPs. The most prominent of these are the HTML tag library, the Bean tag library, and the Logic tag library. JSTL and the Expression Language (EL) in Servlet 2.4 are often used to replace the Bean and Logic tag libraries. Struts 2 comes with a tag library that covers all. You don't need JSTL either, even though in some cases you may still need the EL.

• In Struts 1 you used Struts configuration files, the main of which is called struts-config.xml (by default) and located in the WEB-INF directory of the application. In Struts 2 you use multiple configuration files too, however they must reside in or a subdirectory of WEB-INF/classes.

• Java 5 and Servlet 2.4 are the prerequisites for Struts 2. Java 5 is needed because annotations, added to Java 5, play an important role in Struts 2. Considering that Java 6 has been released and Java 7 is on the way at the time of writing, you're probably already using Java 5 or Java 6.

• Struts 1 action classes must extend org.apache.struts.action.Action. In Struts 2 any POJO can be an action class. However, for reasons that will be explained in Chapter 3, "Actions and Results" it is convenient to extend the ActionSupport class in Struts 2. On top of that, an action class can be used to service related actions.

• Instead of the JSP Expression Language and JSTL, you use OGNL to display object models in JSPs.

• Tiles, which started life as a subcomponent of Struts 1, has graduated to an independent Apache project. It is still available in Struts 2 as a plug-in.



0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More