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

上传人:痛*** 文档编号:128215921 上传时间:2022-08-01 格式:DOC 页数:12 大小:206KB
收藏 版权申诉 举报 下载
毕业论文外文翻译-Struts 开发的最佳实践_第1页
第1页 / 共12页
毕业论文外文翻译-Struts 开发的最佳实践_第2页
第2页 / 共12页
毕业论文外文翻译-Struts 开发的最佳实践_第3页
第3页 / 共12页
资源描述:

《毕业论文外文翻译-Struts 开发的最佳实践》由会员分享,可在线阅读,更多相关《毕业论文外文翻译-Struts 开发的最佳实践(12页珍藏版)》请在装配图网上搜索。

1、Best practices for Struts developmentPalaniyappan Thiagarajan, Pagadala SureshStruts: A brief introductionStruts, 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 li

2、ke Java Servlets, JavaBeans, ResourceBundles, and XML, and it provides flexible and extensible components. Struts implements the Controller layer in the form ofActionServletand recommends building the View layer using JSP tag libraries. Struts also provides a wrapper around the Model layer throughAc

3、tionclasses. Figure 1 illustrates the Struts framework based on the Model-View-Controller design.Figure 1. Struts and MVCOverview of Struts componentsFirst, well explain the Struts components in the context of best practices and the role each one plays in your Web application development.ActionEvery

4、Actionof your application extends Strutsorg.apache.struts.action.Action. TheseActionclasses provide an interface to the applications Model layer, acting as a wrapper around the business logic. EachActionclass must provide its case-specific implementation to theperform()method. Theperform()method alw

5、ays returns a value of typeActionForward.ActionFormEveryActionFormof your application extends Strutsorg.apache.struts.action.ActionForm.ActionForms are simple JavaBeans that encapsulate and validate request parameters. To validate your request data, yourActionFormsvalidate()method must give a case-s

6、pecific implementation.ActionForms serve as a carrier of request data to theActionclass. A JSP object combines with a respectiveActionFormto form your applications View layer, where almost every form field of the JSP object maps to an attribute of the correspondingActionForm.JSP custom tag libraries

7、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-like fashion. You can easily maintain t

8、he JSP components by minimizing the use of Java scriptlets in them. The JSP tags that Struts provides include HTML, logic, and bean tags.ActionErrorsYou useActionErrors to support exception handling. AnActionErrortraps and propagates an application exception to the View layer. Each one is a collecti

9、on ofActionErrorinstances.ActionErrors encapsulate error messages, while thein the Presentation layer renders all error messages in theActionErrorcollection.Best Practice 1. Reuse data across multiple ActionFormsNow that you are familiar with the Struts components, we will continue by showing you wa

10、ys to get the most out of the framework. First, Struts recommends that you associate every JSP object with anActionForm, which encapsulates data represented in the screen. You access the form data in the JSP object using accessory methods found inActionForm. Listing 1 shows the conventional use ofAc

11、tionFormtag in the View layer.Listing 1. Using ActionForm in JSP TheActionFormcalled BP1AForm includes the attributeattrib1, as well as its getter and setter methods. In the configuration filestruts-config.xml, the action /bp1 maps tobp1AFormusing thenameattribute. This facilitates data display in t

12、he JSP.To implement this best practice, Struts recommends you do two things:1. Create a JavaBean (BP1BForm) with attributes that form an attribute subset inBP1AForm, along with the attributes getter and setter methods.2. Replace the attributes inBP1AFormwith the beanBP1BFormby associating the bean w

13、ithBP1AForm. Now you can access this attribute subset inBP1AFormthroughBP1BForm. Listing 2 shows you how.Listing 2. Accessing form attributes in JSP Best Practice 2. Use Action class to handle requestsTypically when using the Struts framework, for every action the JSP component requests your applica

14、tion to execute, the application must extend Strutsorg.apache.struts.action.Actionto create anActionclass. This individualActionclass interfaces with the applications Model layer while processing the request.To implement this practice, Struts recommends you follow these steps:1. Create anActionclass

15、, sayBP2Action, by extendingorg.apache.struts.action.Action.2. Create all otherActionclasses in your Web application by extendingBP2Action.3. InBP2Action, create a methodperformTask(), as in public abstractActionForward performTask(ActionMapping mapping, ActionForm form, HttpServletRequest request,

16、HttpServletResponse response) throws IOException, ServletException.4. InBP2Actionadd one or more generic methods to the application, for exampleserverSideValidate(). You can decide on the methods access modifier by considering the following factors:o If allActionclasses must implement this method, m

17、ake it abstract.o If someActionclasses will provide a case-specific implementation, declare the method protected and give it a default implementation.5. InBP2Action, declare methodperform()as final. Invoke the above generic method, which must always be called before processing the request. Now call

18、the methodperformTask()created instep 3.6. In everyActionclass extendingBP2Action, add methodperformTask()with a case-specific implementation.AdvantagesThis practice has two main advantages. First, it helps you avoid redundant code in everyActionclass of your Web application. Second, it gives the ap

19、plication more control over generic tasks by centralizing the behavior in oneActionclass.Best Practice 3. Use ActionForm to work on session dataIn a Struts-based Web application, eachActionFormextendsorg.apache.struts.action.ActionForm. TheseActionForms encapsulate page data and provide a validation

20、 framework to validate request parameters.Most Web applications maintain data in session to make them available throughout the application. This best practice addresses this Web application feature. It allows methodstoSession()andfromSession()to move session data to and from the form data. Thus, it

21、addresses session data maintenance in a Web application.To adhere to this practice, follow these steps:1. Create an abstract class namedBP3Formby extendingorg.apache.struts.action.ActionForm.2. InBP3Form, add methods with access modifiers as in public abstractvoid toSession(SessionData sessionData)a

22、ndvoid fromSession(SessionData sessionData).3. In everyActionForm, extendBP3Formand implement the abstract methods in which the form data is transported to and from the session.4. The correspondingActionclass may determine the order in which these methods are called. For example, you could invoke me

23、thodtoSession()on theActionFormjust beforeactionForwardis determined.When to use this practiceThis practice is most useful when session data is maintained as a single object and/or every page manipulates or uses session data.Best Practice 4. Handle exceptions effectivelyConventionally, when an appli

24、cation exception occurs in anActionclass, the exception is first logged. Then the class creates anActionErrorand stores it in the appropriate scope. ThisActionclass then forwards control to the appropriateActionForward. Listing 3 shows howActionclass handles exceptions.Listing 3. Exception handling

25、in an Action class try /Code in Action class catch (ApplicationException e) /log exception ActionErrors actionErrors = new ActionErrors(); ActionError actionError = new ActionError(e.getErrorCode(); actionErrors.add(ActionErrors.GLOBAL_ERROR, actionError); saveErrors(request, actionErrors); While co

26、nventional exception handling procedures save exception information in everyActionclass, best practice 4 aims to avoid redundant code while handling exceptions.To use this practice, Struts recommends following these steps:1. Create anActionclass, sayBP4Action, by extendingorg.apache.struts.action.Ac

27、tion.2. Create all otherActionclasses in your Web application by extendingBP4Action.3. InBP4Action, declare variableActionErrors actionErrors = new ActionErrors();.4. InBP4Action, create a methodperformTask()as in public abstractActionForward performTask(ActionMapping mapping, ActionForm form, HttpS

28、ervletRequest request, HttpServletResponse response, ActionErrors actionErrors) throws IOException, ServletException.5. InBP4Action, declare methodperform()as final. Then invoke generic methods, which must always be called before processing the request. Now you can call the methodperformTask()create

29、d in the previous step.6. While implementing methodperformTask()in everyActionclass (by extendingBP4Action), 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 a

30、ctionErrors actionErrors.add(ActionErrors.GLOBAL_ERROR, new ActionError(appException.getErrorCode(); InBP4Action, after invoking the methodperformTask(), save theActionErrorsusingsaveErrors(request, errors).AdvantagesThis practices main advantage is that it avoids code redundancy in everyActionclass

31、 that handlesActionErrors.In conclusionBuilding an easily maintainable Web application can be one of the most challenging tasks for a development team. Using a mature framework like Struts helps you implement the infrastructure code normally associated with building an application. The Struts framew

32、ork provides a set of standard interfaces for plugging business logic into the application, a consistent 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.Thes

33、e four best practices are important for you to extract more from the frameworks features. You, as a developer, can benefit from these lessons to increase your code modularity and application reusability, plus minimize code redundancy. These are all critical to building an extensible Web application.

34、译文Struts 开发的最佳实践Palaniyappan Thiagarajan, Pagadala SureshStruts:简介Struts 是一种开源框架,可用来构建 Web 应用程序,它基于流行的 Model-View-Controller (MVC2) 设计范型。该框架构建在一些标准的技术之上,比如 Java Servlets、JavaBeans、ResourceBundles 和 XML,并且可提供灵活和可扩展的组件。Struts 以ActionServlet的形式实现了 Controller 层,并建议使用 JSP 标记库构建 View 层。Struts 通过Action类提供了

35、围绕 Model 层的包装器。图 1 展示了基于 Model-View-Controller 设计的 Struts 框架。图 1. Struts 和 MVCStruts 组件概览首先,我们在最佳实践上下文中解释 Struts 组件,以及它们在 Web 应用程序开发中所起的作用。Action应用程序的每个Action都会扩展 Struts 的org.apache.struts.action.Action类。这些Action类为应用程序的 Model 层提供了一个接口,充当围绕业务逻辑的包装器。每个Action类都必须向perform()方法提供其特定于用例的实现。perform()方法经常返回类

36、型ActionForward的一个值。ActionForm应用程序的ActionForm扩展了 Struts 的org.apache.struts.action.ActionForm类。ActionForm是一些封装和验证请求参数的简单 JavaBean。要验证请求数据,ActionForm的validate()方法必须给出一个特定于该情况的实现。ActionForm作为运载工具,向Action类提供请求数据。一个 JSP 对象与各自的ActionForm对象相结合,构成应用程序的 View 层。在该层,几乎 JSP 对象的每个表单字段都映射到相应的ActionForm的属性。JSP 定制标记

37、库JSP 定制标记库是用标记表示的一组行为的集合。这是 JSP Specification 1.1 的一个强大特性;它将其他应用程序层的表示区别了开来。这些库易于使用,而且可以以一种类似 XML 的方式来读取。只要尽量少地在其中使用 Java scriptlet,就可以轻松维护 JSP 组件。Struts 提供的 JSP 标记包括 HTML、逻辑和 bean 标记。ActionErrors可以使用ActionError来支持异常处理。ActionError捕捉应用程序异常,并将其传送给 View 层。每个异常都是一个ActionError实例的集合。ActionError可以封装错误消息,而

38、Presentation 层中的可以呈现ActionError集合内的所有错误消息。最佳实践 1. 跨多个 ActionForm 重用数据熟悉了 Struts 组件之后,就可以继续学习如何充分利用这一框架。首先,Struts 建议将每个 JSP 对象与一个ActionForm相关联,后者可以封装屏幕上显示的数据。可以通过ActionForm内的附加方法来访问 JSP 对象内的表单数据。清单 1 展示了ActionForm标记在 View 层中的传统方法。清单 1. 使用 ActionForm 这个ActionForm被称为 “BP1AForm”,它包括属性attrib1及其 getter 和

39、setter 方法。在配置文件struts-config.xml中,行为 “/bp1” 通过name属性映射到bp1AForm。这有助于在 JSP 中显示数据。要实现这一最佳实践,Struts 建议您进行以下两个操作:1. 创建一个 JavaBean(BP1BForm),且其属性是BP1AForm属性的子集,还要创建这些属性的 getter 和 setter 方法。2. 通过将这个 bean 与BP1AForm关联,用 beanBP1BForm的属性替代BP1AForm中的属性。现在就可以通过BP1BForm访问BP1AForm中的属性子集了。清单 2 展示了访问的方式。清单 2. 访问 JS

40、P 中的表单属性 最佳实践 2. 使用 Action 类处理请求通常,在使用这个 Struts 框架时,对于 JSP 组件请求应用程序执行的每个动作,应用程序都必须扩展 Struts 的org.apache.struts.action.Action以创建Action类。在处理请求时,单个的Action类与应用程序的 Model 层连接。要实现这一最佳实践,Struts 建议您遵循以下步骤:1. 通过扩展org.apache.struts.action.Action创建一个Action类,比如BP2Action。2. 通过扩展BP2Action在 Web 应用程序中创建所有其他Action类。3

41、. 在BP2Action类中创建一个方法performTask(),就像在公共抽象类ActionForward performTask(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException中一样。4. 在BP2Action类中向应用程序添加一个或多个泛型方法,比如serverSideValidate()。考虑以下因素后决定方法的访问修饰符:o 如果所有Action类都必须实现此方法

42、,则让其为抽象。o 如果某些Action类提供一个特定的实现,则将此方法声明为受保护,并给它一个默认实现。5. 在BP2Action类中,将方法perform()声明为 final。调用上述的泛型方法(通常在处理请求前调用该方法)。现在调用步骤 3中创建的方法performTask()。6. 在每个扩展BP2Action的Action类,添加具有特定实现的方法performTask()。优势这一实践有两个主要优势。首先,它避免了 Web 应用程序中每个Action类的冗余代码。其次,通过将Action类的行为集中在一起,使应用程序能够更多地控制通用的任务。最佳实践 3. 使用 ActionFo

43、rm 处理会话数据在一个基于 Struts 的 Web 应用程序中,每个ActionForm都扩展org.apache.struts.action.ActionForm类。这些ActionForm封装页面数据,并提供一个验证框架来验证请求参数。大多数 Web 应用程序都在会话中保持数据,使其在整个应用程序过程中可用。这种最佳实践实现了这种 Web 应用程序特性。它允许方法toSession()和fromSession()将会话数据移动到表单数据或从表单数据移回。因此,它实现了在 Web 应用程序中保持会话数据。要遵循一最佳实践,执行以下步骤:1. 通过扩展org.apache.struts.a

44、ction.ActionForm创建一个名为BP3Form的抽象类。2. 在BP3Form类中,添加具有访问修饰语的方法,就像在公共抽象类void toSession(SessionData sessionData)和void fromSession(SessionData sessionData)中一样。3. 在每个ActionForm类中,扩展BP3Form并实现这些抽象方法(表单数据通过它们传递到会话或从会话传回)。4. 相应的Action类可以决定这些方法的调用顺序。例如,可以在决定actionForward之前调用ActionForm上的方法toSession()。何时使用这一实践这

45、一实践最适用于:会话数据是单一对象和/或每个页操作或使用会话数据。最佳实践 4. 有效处理异常传统地,当在Action类中发生应用程序异常时,异常首先被写入日志。然后此类创建一个ActionError并在合适的作用域中存储它。然后Action类再将控制转交给合适的ActionForward。清单 3 展示了Action类是如何处理异常的。清单 3. Action 类中的异常处理 try /Code in Action class catch (ApplicationException e) /log exception ActionErrors actionErrors = new Actio

46、nErrors(); ActionError actionError = new ActionError(e.getErrorCode(); actionErrors.add(ActionErrors.GLOBAL_ERROR, actionError); saveErrors(request, actionErrors); 传统的异常处理过程在每个Action类中保存异常信息,而最佳实践 4 则在处理异常时避免冗余代码。要使用这一最佳实践,Struts 建议您遵循以下步骤:1. 通过扩展org.apache.struts.action.Action创建一个Action类,比如BP4Actio

47、n。2. 通过扩展BP4Action在 Web 应用程序中创建所有其他Action类。3. 在BP4Action中声明变量ActionErrors actionErrors = new ActionErrors();。4. 在BP4Action中创建方法performTask(),就像在公共抽象类ActionForward performTask(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, ActionErrors actionErrors)

48、throws IOException, ServletException中一样。5. 在BP4Action中将方法perform()声明为 final。然后调用泛型方法(这些方法总是在处理请求前调用)。现在调用在前一个步骤中创建的performTask()。6. 在每个Action类中实现方法performTask()的同时(通过扩展BP4Action),像清单 4 那样处理应用程序异常。清单 4. 有效使用 ActionErrors try /Code in Action class catch(ApplicationException appException) /Log exceptio

49、n /Add error to actionErrors actionErrors.add(ActionErrors.GLOBAL_ERROR, new ActionError(appException.getErrorCode(); 在BP4Action中,调用方法performTask()之后,通过saveErrors(request, errors)保存ActionErrors。优势这一实践主要的优势是:避免了每个处理ActionErrors的Action类中的代码冗余。结束语对开发团队而言,构建易于维护的 Web 应用程序是一项非常具有挑战性的任务。使用 Struts 等成熟的框架有助

50、于实现通常与构建应用程序相关的基础设施代码。Struts 框架提供了一组标准接口,用于将业务逻辑插入到应用程序中。此外,还提供了一种跨开发团队的一致机制,用于执行用户数据验证、屏幕导航等任务,以及用于简化开发屏幕的一组定制标记库。本文给出的 4 种最佳实践对您充分利用这种框架的特性十分重要。它们不仅能够提高代码的模块化程度和应用程序的可重用性,还能减少代码冗余。对于构建可扩展的 Web 应用程序,这是至关重要的。本文译自: developerWorksWeb development Technical library五分钟搞定5000字毕业论文外文翻译,你想要的工具都在这里!在科研过程中阅读翻

51、译外文文献是一个非常重要的环节,许多领域高水平的文献都是外文文献,借鉴一些外文文献翻译的经验是非常必要的。由于特殊原因我翻译外文文献的机会比较多,慢慢地就发现了外文文献翻译过程中的三大利器:Google“翻译”频道、金山词霸(完整版本)和CNKI“翻译助手。具体操作过程如下: 1.先打开金山词霸自动取词功能,然后阅读文献; 2.遇到无法理解的长句时,可以交给Google处理,处理后的结果猛一看,不堪入目,可是经过大脑的再处理后句子的意思基本就明了了; 3.如果通过Google仍然无法理解,感觉就是不同,那肯定是对其中某个“常用单词”理解有误,因为某些单词看似很简单,但是在文献中有特殊的意思,这

52、时就可以通过CNKI的“翻译助手”来查询相关单词的意思,由于CNKI的单词意思都是来源与大量的文献,所以它的吻合率很高。 另外,在翻译过程中最好以“段落”或者“长句”作为翻译的基本单位,这样才不会造成“只见树木,不见森林”的误导。四大工具: 1、Google翻译: google,众所周知,谷歌里面的英文文献和资料还算是比较详实的。我利用它是这样的。一方面可以用它查询英文论文,当然这方面的帖子很多,大家可以搜索,在此不赘述。回到我自己说的翻译上来。下面给大家举个例子来说明如何用吧比如说“电磁感应透明效应”这个词汇你不知道他怎么翻译,首先你可以在CNKI里查中文的,根据它们的关键词中英文对照来做,

53、一般比较准确。 在此主要是说在google里怎么知道这个翻译意思。大家应该都有词典吧,按中国人的办法,把一个一个词分着查出来,敲到google里,你的这种翻译一般不太准,当然你需要验证是否准确了,这下看着吧,把你的那支离破碎的翻译在google里搜索,你能看到许多相关的文献或资料,大家都不是笨蛋,看看,也就能找到最精确的翻译了,纯西式的!我就是这么用的。 2、CNKI翻译: CNKI翻译助手,这个网站不需要介绍太多,可能有些人也知道的。主要说说它的有点,你进去看看就能发现:搜索的肯定是专业词汇,而且它翻译结果下面有文章与之对应(因为它是CNKI检索提供的,它的翻译是从文献里抽出来的),很实用的

54、一个网站。估计别的写文章的人不是傻子吧,它们的东西我们可以直接拿来用,当然省事了。网址告诉大家,有兴趣的进去看看,你们就会发现其乐无穷!还是很值得用的。 3、网路版金山词霸(不到1M): 4、有道在线翻译:翻译时的速度:这里我谈的是电子版和打印版的翻译速度,按个人翻译速度看,打印版的快些,因为看电子版本一是费眼睛,二是如果我们用电脑,可能还经常时不时玩点游戏,或者整点别的,导致最终SPPEED变慢,再之电脑上一些词典(金山词霸等)在专业翻译方面也不是特别好,所以翻译效果不佳。在此本人建议大家购买清华大学编写的好像是国防工业出版社的那本英汉科学技术词典,基本上挺好用。再加上网站如:google

55、CNKI翻译助手,这样我们的翻译速度会提高不少。具体翻译时的一些技巧(主要是写论文和看论文方面) 大家大概都应预先清楚明白自己专业方向的国内牛人,在这里我强烈建议大家仔细看完这些头上长角的人物的中英文文章,这对你在专业方向的英文和中文互译水平提高有很大帮助。 我们大家最蹩脚的实质上是写英文论文,而非看英文论文,但话说回来我们最终提高还是要从下大工夫看英文论文开始。提到会看,我想它是有窍门的,个人总结如下: 1、把不同方面的论文分夹存放,在看论文时,对论文必须做到看完后完全明白(你重视的论文);懂得其某部分讲了什么(你需要参考的部分论文),在看明白这些论文的情况下,我们大家还得紧接着做的工作就是

56、把论文中你觉得非常巧妙的表达写下来,或者是你论文或许能用到的表达摘记成本。这个本将是你以后的财富。你写论文时再也不会为了一些表达不符合西方表达模式而烦恼。你的论文也降低了被SCI或大牛刊物退稿的几率。不信,你可以试一试 2、把摘记的内容自己编写成检索,这个过程是我们对文章再回顾,而且是对你摘抄的经典妙笔进行梳理的重要阶段。你有了这个过程。写英文论文时,将会有一种信手拈来的感觉。许多文笔我们不需要自己再翻译了。当然前提是你梳理的非常细,而且中英文对照写的比较详细。 3、最后一点就是我们往大成修炼的阶段了,万事不是说成的,它是做出来的。写英文论文也就像我们小学时开始学写作文一样,你不练笔是肯定写不出好作品来的。所以在此我鼓励大家有时尝试着把自己的论文强迫自己写成英文的,一遍不行,可以再修改。最起码到最后你会很满意。呵呵,我想我是这么觉得的。

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!