外文翻译----Struts开发的最佳实践
《外文翻译----Struts开发的最佳实践》由会员分享,可在线阅读,更多相关《外文翻译----Struts开发的最佳实践(9页珍藏版)》请在毕设资料网上搜索。
1、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 Model-View-Controller (MVC2) design paradigm. The framework is built upon standard technologies
2、 like Java Servlets, JavaBeans, ResourceBundles, and XML, and it provides flexible and extensible components. Struts implements the Controller layer in the form of ActionServlet and recommends building the View layer using JSP tag libraries. Struts also provides a wrapper around the Model layer thro
3、ughAction classes. Figure 1 illustrates the Struts framework based on the Model-View-Controller design. Figure 1. Struts and MVC Overview of Struts components First, well explain the Struts components in the context of best practices and the role each one plays in your Web application development. A
4、ction Every Action of your application extends Struts org.apache.struts.action.Action. These Action classes provide an interface to the applications Model layer, acting as a wrapper around the business logic. Each Action class must provide its case-specific implementation to the perform() method. Th
5、e perform() method always returns a value of type ActionForward. ActionForm Every ActionForm of your application extends Struts org.apache.struts.action.ActionForm. ActionForms are simple JavaBeans that encapsulate and validate request parameters. To validate your request data, your ActionForms vali
6、date() method must give a case-specific implementation. ActionForms serve as a carrier of request data to the Action class. A JSP object combines with a respective ActionForm to form your applications View layer, where almost every form field of the JSP object maps to an attribute of the correspondi
7、ng 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 1.1; it allows you to separate presentation from other application tiers. The libraries are easy to use and you can read them in XML
8、-like fashion. You can easily maintain the JSP components by minimizing the use of Java scriptlets in them. The JSP tags that Struts provides include HTML, logic, and bean tags. ActionErrors You use ActionErrors to support exception handling. An ActionError traps and propagates an application except
9、ion to the View layer. Each one is a collection of ActionError instances. ActionErrors encapsulate error messages, while the in the Presentation layer renders all error messages in the ActionError collection. Best Practice 1. Reuse data across multiple ActionForms Now that you are familiar with the
10、Struts components, we will continue by showing you ways to get the most out of the framework. First, Struts recommends that you associate every JSP object with an ActionForm, which encapsulates data represented in the screen. You access the form data in the JSP object using accessory methods found i
11、n ActionForm. Listing 1 shows the conventional use of ActionForm tag in the View layer. Listing 1. Using ActionForm in JSP The ActionForm called BP1AForm includes the attribute attrib1, as well as its getter and setter methods. In the configuration filestruts-config.xml, the action /bp1 maps to bp1A
12、Form using the name attribute. This facilitates data display in the JSP. To implement this best practice, Struts recommends you do two things: 1. Create a JavaBean (BP1BForm) with attributes that form an attribute subset in BP1AForm, along with the attributes getter and setter methods. 2. Replace th
13、e 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 Best Practice 2. Use Action class to handle requests Typically when using
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中设计图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 外文 翻译 struts 开发 最佳 最好 实践
