【正文】
ent mechanism across development teams for performing tasks such as user data validation, screen navigation, and so forth, as well as a set of custom tag libraries to simplify developing screens. These four best practices are important for you to extract more from the framework39。. 4. In BP4Action, create a method performTask() as in public abstract ActionForward performTask(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, ActionErrors actionErrors) throws IOException, ServletException. 5. In BP4Action, declare method perform() as final. Then invoke generic methods, which must always be called before processing the request. Now you can call the method performTask() created in the previous step. 6. While implementing method performTask() in every Action class (by extending BP4Action), handle application exceptions as shown in Listing 4. Listing 4. Using ActionErrors effectively try { //Code in Action class } catch(ApplicationException appException) { //Log exception //Add error to actionErrors (, new ActionError(()))。 saveErrors(request, actionErrors)。 ActionError actionError = new ActionError(())。s Model layer while processing the request. To implement this practice, Struts remends you follow these steps: 1. Create an Action class, say BP2Action, by extending . 2. Create all other Action classes in your Web application by extending BP2Action. 3. In BP2Action, create a method performTask(), as in public abstract ActionForward performTask(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException. 4. In BP2Action add one or more generic methods to the application, for example serverSideValidate(). You can decide on the method39。 getter and setter methods. 2. Replace the attributes in BP1AForm with the bean BP1BForm by associating the bean with BP1AForm. Now you can access this attribute subset in BP1AForm through BP1BForm. Listing 2 shows you how. Listing 2. Accessing form attributes in JSP html:form action=/bp1 bean:define name=bp1AForm property=bp1BForm id=bp1B type= / html:text name=bp1B property=subsetAtt1 / /html:form Best Practice 2. Use Action class to handle requests Typically when using the Struts framework, for every action the JSP ponent requests your application to execute, the application must extend Struts39。s View layer, where almost every form field of the JSP object maps to an attribute of the corresponding ActionForm. JSP custom tag libraries The JSP custom tag libraries are a collection of actions presented as tags. This is a powerful feature of the JSP Specification 。 . ActionForms are simple JavaBeans that encapsulate and validate request parameters. To validate your request data, your ActionForm39。 . These Action classes provide an interface to the application39。Best practices for Struts development Palaniyappan Thiagarajan, Pagadala Suresh Struts: A brief introduction Struts, an open source framework you can use to build Web applications, is based on the popular ModelViewController (MVC2