基于hibernate和struts的选课排课系统毕业设计英文文献翻译.doc

上传人:laozhun 文档编号:2387342 上传时间:2023-02-17 格式:DOC 页数:9 大小:61.50KB
返回 下载 相关 举报
基于hibernate和struts的选课排课系统毕业设计英文文献翻译.doc_第1页
第1页 / 共9页
基于hibernate和struts的选课排课系统毕业设计英文文献翻译.doc_第2页
第2页 / 共9页
基于hibernate和struts的选课排课系统毕业设计英文文献翻译.doc_第3页
第3页 / 共9页
基于hibernate和struts的选课排课系统毕业设计英文文献翻译.doc_第4页
第4页 / 共9页
基于hibernate和struts的选课排课系统毕业设计英文文献翻译.doc_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《基于hibernate和struts的选课排课系统毕业设计英文文献翻译.doc》由会员分享,可在线阅读,更多相关《基于hibernate和struts的选课排课系统毕业设计英文文献翻译.doc(9页珍藏版)》请在三一办公上搜索。

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 重用数据待添加的隐藏文字内容2熟悉了 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 performTas

29、k(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException中一样。4. 在BP2Action类中向应用程序添加一个或多个泛型方法,比如serverSideValidate()。考虑以下因素后决定方法的访问修饰符:o 如果所有Action类都必须实现此方法,则让其为抽象。o 如果某些Action类提供一个特定的实现,则将此方法声明为受保护,并给它一个默认实现。5. 在BP2Action

30、类中,将方法perform()声明为 final。调用上述的泛型方法(通常在处理请求前调用该方法)。现在调用步骤 3中创建的方法performTask()。6. 在每个扩展BP2Action的Action类,添加具有特定实现的方法performTask()。优势这一实践有两个主要优势。首先,它避免了 Web 应用程序中每个Action类的冗余代码。其次,通过将Action类的行为集中在一起,使应用程序能够更多地控制通用的任务。最佳实践 3. 使用 ActionForm 处理会话数据在一个基于 Struts 的 Web 应用程序中,每个ActionForm都扩展org.apache.struts

31、.action.ActionForm类。这些ActionForm封装页面数据,并提供一个验证框架来验证请求参数。大多数 Web 应用程序都在会话中保持数据,使其在整个应用程序过程中可用。这种最佳实践实现了这种 Web 应用程序特性。它允许方法toSession()和fromSession()将会话数据移动到表单数据或从表单数据移回。因此,它实现了在 Web 应用程序中保持会话数据。要遵循一最佳实践,执行以下步骤:1. 通过扩展org.apache.struts.action.ActionForm创建一个名为BP3Form的抽象类。2. 在BP3Form类中,添加具有访问修饰语的方法,就像在公共

32、抽象类void toSession(SessionData sessionData)和void fromSession(SessionData sessionData)中一样。3. 在每个ActionForm类中,扩展BP3Form并实现这些抽象方法(表单数据通过它们传递到会话或从会话传回)。4. 相应的Action类可以决定这些方法的调用顺序。例如,可以在决定actionForward之前调用ActionForm上的方法toSession()。最佳实践 4. 有效处理异常传统地,当在Action类中发生应用程序异常时,异常首先被写入日志。然后此类创建一个ActionError并在合适的作用域中存储它。然后Action类再将控制转交给合适的ActionForward。清单 3 展示了Action类是如何处理异常的。结束语 对开发团队而言,构建易于维护的 Web 应用程序是一项非常具有挑战性的任务。使用 Struts 等成熟的框架有助于实现通常与构建应用程序相关的基础设施代码。Struts 框架提供了一组标准接口,用于将业务逻辑插入到应用程序中。此外,还提供了一种跨开发团队的一致机制,用于执行用户数据验证、屏幕导航等任务,以及用于简化开发屏幕的一组定制标记库。

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号