欢迎来到毕设资料网! | 帮助中心 毕设资料交流与分享平台
毕设资料网
全部分类
  • 毕业设计>
  • 毕业论文>
  • 外文翻译>
  • 课程设计>
  • 实习报告>
  • 相关资料>
  • ImageVerifierCode 换一换
    首页 毕设资料网 > 资源分类 > DOC文档下载
    分享到微信 分享到微博 分享到QQ空间

    外文翻译----Struts开发的最佳实践

    • 资源ID:125151       资源大小:97KB        全文页数:9页
    • 资源格式: DOC        下载积分:100金币
    快捷下载 游客一键下载
    账号登录下载
    三方登录下载: QQ登录
    下载资源需要100金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。

    外文翻译----Struts开发的最佳实践

    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

    14、 the Struts framework, for every action the JSP component requests your application to execute, the application must extend Struts org.apache.struts.action.Action to create an Action class. This individual Action class interfaces with the applications Model layer while processing the request. To imp

    15、lement this practice, Struts recommends you follow these steps: 1. Create an Action class, say BP2Action, by extending org.apache.struts.action.Action. 2. Create all other Action classes in your Web application by extending BP2Action. 3. In BP2Action, create a method performTask(), as in public abst

    16、ract 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 methods a

    17、ccess modifier by considering the following factors: o If all Action classes must implement this method, make it abstract. o If some Action classes will provide a case-specific implementation, declare the method protected and give it a default implementation. 5. In BP2Action, declare method perform(

    18、) as final. Invoke the above generic method, which must always be called before processing the request. Now call the method performTask() created in step 3. 6. In every Action class extending BP2Action, add method performTask() with a case-specific implementation. Advantages This practice has two ma

    19、in advantages. First, it helps you avoid redundant code in every Action class of your Web application. Second, it gives the application more control over generic tasks by centralizing the behavior in one Action class. Best Practice 3. Use ActionForm to work on session data In a Struts-based Web appl

    20、ication, each ActionForm extends org.apache.struts.action.ActionForm. These ActionForms encapsulate page data and provide a validation framework to validate request parameters. Most Web applications maintain data in session to make them available throughout the application. This best practice addres

    21、ses this Web application feature. It allows methods toSession() and fromSession() to move session data to and from the form data. Thus, it addresses session data maintenance in a Web application. To adhere to this practice, follow these steps: 1. Create an abstract class named BP3Form by extending o

    22、rg.apache.struts.action.ActionForm. 2. In BP3Form, add methods with access modifiers as in public abstract void toSession(SessionData sessionData) and void fromSession(SessionData sessionData). 3. In every ActionForm, extend BP3Form and implement the abstract methods in which the form data is transp

    23、orted to and from the session. 4. The corresponding Action class may determine the order in which these methods are called. For example, you could invoke method toSession() on the ActionForm just before actionForward is determined. When to use this practice This practice is most useful when session

    24、data is maintained as a single object and/or every page manipulates or uses session data. Best Practice 4. Handle exceptions effectively Conventionally, when an application exception occurs in an Action class, the exception is first logged. Then the class creates anActionError and stores it in the a

    25、ppropriate scope. This Action class then forwards control to the appropriate ActionForward. Listing 3 shows how Action class handles exceptions. Listing 3. Exception handling in an Action class try /Code in Action class catch (ApplicationException e) /log exception ActionErrors actionErrors = new Ac

    26、tionErrors(); ActionError actionError = new ActionError(e.getErrorCode(); actionErrors.add(ActionErrors.GLOBAL_ERROR, actionError); saveErrors(request, actionErrors); While conventional exception handling procedures save exception information in every Action class, best practice 4 aims to avoid redundant code while handling exceptions. To use this practice, Struts recommends following these steps:


    注意事项

    本文(外文翻译----Struts开发的最佳实践)为本站会员(泛舟)主动上传,毕设资料网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请联系网站客服QQ:540560583,我们立即给予删除!




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们
    本站所有资料均属于原创者所有,仅提供参考和学习交流之用,请勿用做其他用途,转载必究!如有侵犯您的权利请联系本站,一经查实我们会立即删除相关内容!
    copyright@ 2008-2025 毕设资料网所有
    联系QQ:540560583