版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、毕业设计说明书英文文献及中文翻译学生姓名: 学号: 学 院: 专 业: 指导教师: best practices for struts developmentstruts: 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 l
2、ike 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 througha
3、ctionclasses. figure 1 illustrates the struts framework based on the model-view-controller design.figure 1. struts and mvcoverview 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.actioneve
4、ryactionof 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 a
5、lways 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
6、-specific 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 librari
7、esthe 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
8、 the jsp components by minimizing the use of java scriptlets in them. the jsp tags that struts provides include html, logic, and bean tags.best practice 1. reuse data across multiple actionformsnow that you are familiar with the struts components, we will continue by showing you ways to get the most
9、 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 ofaction formtag in th
10、e view layer.best practice 2. use action class to handle requeststypically when using the struts framework, for every action the jsp component requests your application to execute, the application must extend strutsorg apache struts.action.actionto create anactionclass. this individualactionclass in
11、terfaces with the applications model layer while processing the request.to implement this practice, struts recommends you follow these steps:1. create anactionclass, saybp2action, by extendingorg.apache.struts.action.action.2. create all otheractionclasses in your web application by extendingbp2acti
12、on.3. inbp2action, create a methodperformtask(), as in public abstractactionforward performtask(actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) throws ioexception, servletexception.4. inbp2actionadd one or more generic methods to the application, for
13、 exampleserversidevalidate(). you can decide on the methods access modifier by considering the following factors:o if allactionclasses must implement this method, make it abstract.o if someactionclasses will provide a case-specific implementation, declare the method protected and give it a default i
14、mplementation.5. inbp2action, declare methodperform()as final. invoke the above generic method, which must always be called before processing the request. now call the methodperformtask()created instep 3.6. in everyactionclass extendingbp2action, add methodperformtask()with a case-specific implement
15、ation.advantagesthis practice has two main advantages. first, it helps you avoid redundant code in everyactionclass of your web application. second, it gives the application more control over generic tasks by centralizing the behavior in oneactionclass.best practice 3. use actionform to work on sess
16、ion datamost 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 addresses session data maintenance
17、 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)andvoid fromsession(sessiondata ses
18、siondata).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 methodtosession()on theactionformjus
19、t 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 application exception occurs in anactio
20、nclass, the exception is first logged. then the class creates an action errorand stores it in the appropriate scope. thisactionclass then forwards control to the appropriateaction forward. listing 3 shows howactionclass handles exceptions. in conclusionbuilding an easily maintainable web application
21、 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 framework provides a set of standard interfaces for plugging business logic into the applica
22、tion, 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.these four best practices are important for you to extract more from the frameworks featur
23、es. 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.struts 开发的最佳实践struts:简介 struts是一种开源框架,可用来构建 web 应用程序,它基于流行的(mvc2) 设计范型。该框架构建在一些标准的技术之上
24、,比如 java servlets、javabeans、resourcebundles 和 xml,并且可提供灵活和可扩展的组件。struts 以actionservlet的形式实现了 controller 层,并建议使用 jsp 标记库构建 view 层。struts 通过action类提供了围绕 model 层的包装器。图 1 展示了基于 model-view-controller 设计的 struts 框架。 图 1. struts 和 mvcstruts 组件概览首先,我们在最佳实践上下文中解释 struts 组件,以及它们在 web 应用程序开发中所起的作用。actionaction
25、类为应用程序的 model 层提供了一个接口,充当围绕业务逻辑的包装器。每个action类都必须向perform()方法提供其特定于用例的实现。perform()方法经常返回类型actionforward的一个值。actionformactionform是一些封装和验证请求参数的简单 javabean。要验证请求数据,actionform的validate()方法必须给出一个特定于该情况的实现。它作为运载工具,向action类提供请求数据。一个 jsp 对象与各的actionform对象相结合,构成应用程序的 view 层。在该层,几乎 jsp 对象的每个表单字段都映射到相应的actionfo
26、rm的属性。jsp 定制标记库jsp 定制标记库是用标记表示的一组行为的集合。这是 jsp specification 1.1 的一个强大特性;它将其他应用程序层的表示区别了开来。这些库易于使用,而且可以以一种类似 xml 的方式来读取。只要尽量少地在其中使用 java scriptlet,就可以轻松维护 jsp 组件。struts 提供的 jsp 标记包括 html、逻辑和 bean 标记。actionerrors可以使用actionerror来支持异常处理。actionerror捕捉应用程序异常,并将其传送给 view 层。每个异常都是一个actionerror实例的集合。可以封装错误消息
27、,而 presentation 层中的可以呈现actionerror集合内的所有错误消息。最佳实践 1. 跨多个 actionform 重用数据熟悉了 struts 组件之后,就可以继续学习如何充分利用这一框架。首先,struts 建议将每个 jsp 对象与一个actionform相关联,后者可以封装屏幕上显示的数据。可以通过actionform内的附加方法来访问 jsp 对象内的表单数据。清单 1 展示了actionform标记在 view 层中的传统方法。最佳实践 2. 使用 action 类处理请求通常,在使用这个 struts 框架时,对于 jsp 组件请求应用程序执行的每个动作,应用
28、程序都必须扩展 struts 的org.apache.struts.action.action以创建action类。在处理请求时,单个的action类与应用程序的 model 层连接。要实现这一最佳实践,struts 建议您遵循以下步骤:1. 通过扩展org.apache.struts.action.action创建一个action类,比如bp2action。2. 通过扩展bp2action在 web 应用程序中创建所有其他action类。3. 在bp2action类中创建一个方法performtask(),就像在公共抽象类actionforward performtask(actionmap
29、ping mapping, actionform form, httpservletrequest request, httpservletresponse response) throws ioexception, servletexception中一样。4. 在bp2action类中向应用程序添加一个或多个泛型方法,比如serversidevalidate()。考虑以下因素后决定方法的访问修饰符:o 如果所有action类都必须实现此方法,则让其为抽象。o 如果某些action类提供一个特定的实现,则将此方法声明为受保护,并给它一个默认实现。5. 在bp2action类中,将方法perform()声明为 final。调用上述的泛型方法(通常在处理请求前调用该方法)。现在调用步骤 3中创建的方法performtask()。6. 在每个扩展bp2action的action类,添加具有特定实现的方法performtask()。优势这一实践有两个主要优势。首先,它避免了 web
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024工程装饰合同范本
- 2024彩钢瓦安装合同
- 数字化农业技术选型与应用中的注意事项
- 普外科常见应急演练
- 西安电子科技大学《编译原理》2023-2024学年第一学期期末试卷
- 2024影视拍摄合同范文
- 建筑施工中的交通安全与交通组织措施考核试卷
- 广告与社交媒体市场营销考核试卷
- 小学生女生安全心理教育
- 交通运输的可持续发展模式与路径考核试卷
- 液化石油气站安全隐患检查记录表
- 《颈椎病病人的护理》PPT课件(完整版)
- 两票三制培训.
- 医院药品储备定期评价分析报告及改进措施
- 教练技术一阶段讲义
- 广州供电局输电部高压电缆运行工作介绍
- 实验室审核检查表参照模板
- 三年级上册语文课程纲要.doc
- 做新时代好队员竞选小队长演示PPT课件
- Linux网络管理
- 生命成长,责任担当——主题班会(共26张PPT)
评论
0/150
提交评论