三大框架外文翻译_第1页
三大框架外文翻译_第2页
三大框架外文翻译_第3页
三大框架外文翻译_第4页
三大框架外文翻译_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、一种基于Hibernate、Struts 和Spring的J2EE应用开发框架随着 Java 技术的逐渐成熟与完善 , 作为建立企业级应用的标准平台 ,J2EE 平 台 得到了长足的发展。借助于 J2EE规范中包含的多项技术:Enterprise JavaBean(EJB) 、 Java Servlets(Servlet) 、 Java Server Pages(JSP) 、 Java MessageService(JMS)等,开发出了许多应用系统。但是,在传统 J2EE应用的开 发过 程中也出现了一些问题:(1) 数据模型和逻辑模型之间的矛盾。目前使用的数据库基本上都是关系型数据库,而Jav

2、a本质上是一种面向对象的语言,对象在存储和读取时使用SQ和JDB(进行数据库操作,降低了编程的效率以及系统的可维护性;(2)传统的J2EE应用多采用基于EJB的重量级框架,这种框架适合于开发大型企业应用,但是使用EJB容器进行开发和调试需要耗费大量时间。为了降低代码的耦合性,提高系统的开发效率,本文提出了一种基于 Struts 框架、 Hibernate 框架和 Spring框架的J2EE应用开发策略。Hibernate 框架Hibernate 是一个数据持久层框架,是一种实现对象和关系之间映射( O/RMapping)的工具,它对JDB(进行了轻量级的对象圭寸装,使程序员可以使用对象编程思想

3、来操作数据库。它不仅提供了从Java 类到数据表的映射,也提供了数据查询和恢复机制。相对于使用JDBCSS座操作数据库,使用Hibernate能大大的 提高实现的 效率。 Hibernate 框架用配置文件的形式来定义Java 对象和数据表之 间的映射关系,同时在更深的层面将数据表之间的关系解释为 Java 对象之间的继 承及包含等关系。通过使用 HQ语句将复杂的关系算法用对象的方式描述,在很 大程 度上简化了对数据的查询,加快了开发的效率。在 Hibernate 中有一个简单而直观的API,用于对数据库所表示的对象执行查询。要创建或修改这些对象,只需在程序中与它们进行交互,然后告诉Hiber

4、nate 保存即可。这样,大量圭装 持久化操作的业务逻辑不再需要编写烦琐的JDB(语句,从而使数据持久层得到了极大的简化。用 Struts 实现 MV架构 MVC( Model-View-Controller) 由 Trygve Reenskaug提出,首先被应用在SmallTalk-80 环境中,是许多交互和界面系统的构成基础。根据界面设计可变性的需求,MV把交互系统的组成分解成模型、视图、控制器 三部分。模型(Model)是软件所处理问题逻辑在独立于外在显示内容和形式情况下的内在抽象, 封装了问题的核心数据、 逻辑和功能的计算关系, 独立于具体 的界面表达和I/O操作。视图(View)把表

5、示模型数据及逻辑关系和状态的信息及特定形式展示给用户。 它从模型获得显示信息, 对于相同的信息可以有多个不 同的显示形式或视图。控制器( Controller )是处理用户与软件的交互操作的, 其职责是控制提供模型中任何变化的传播,确保用户界面于模型间的对应联系; 它接受用户的输入,将输入反馈给模型, 进而实现对模型的计算控制, 是使模型 和视图协调工作的部件。 通常一个视图对应一个控制器。 模型、视图与控制器的 分离,使得一个模型可以具有多个显示视图。 如果用户通过某个视图的控制器改 变了模型的数据,所有其它依赖于这些数据的视图都应反映到这些变化。因此, 无论何时发生了何种数据变化, 控制器

6、都会将变化通知所有的视图, 导致显示的 更新。这实际上是一种模型的变化 - 传播机制。Struts 框架Struts 框架最早是作为 ApacheJakarta 项目的组成部分问世运做, 它继承了MV(的各项特t并根据J2EE勺特点,做了相应的变化与扩展。Struts框架很好 的结合了 Jsp , Java Servlet , Java Bean , Taglib 等技术。在Struts 中,承担MVC中控制器角色的是ActionServlet 。 ActionServlet是一个通用的控制组件。这个 控制组件提供了处理所有发送到Struts的HTTP#:的入口点,它截取和分发这些请求到相应的

7、动作类 (这些动作类都是 Action 类的子类) 。另外控制组件也负责用相应的请求参数填充 Action Form(FromBear),并传给动作类(ActionBean )。动作类访问核心商业逻辑,即访问 Java Bear或调用EJB最后动作类把控制权传 给后续的JSP文件,由JSP文件生成视图。所有这些控制逻辑利用Struts-corfig.xml 文件来配置。在 Struts框架中,视图主要由JSF生成页面完成,Struts提供丰富的JSP标签库,这有利于分开表现逻辑和程序逻辑。模型以一个 或多个 Java Bear 的形式存在。在Struts 中,主要存在三种 Bear, 分别是:

8、 Actior ,ActiorForm , EJB或者Java Bear o Struts 框架没有具体定义模型层的实现,在 实际开发中,模型层通常是和业务逻辑紧密相连的, 并且要对底层数据进行操作。Hibernate 引入到 Struts 框架的模型层中,使用它来进行数据封装和映射,提供持久化的支持。Spring 框架Spring 明显区别于其他轻量级application framework, 它将专注于 web 的支持,与 struts 和 webwork 有着明显的区别。在与 struts 、 webwork 的对比上 ,Spring 是一个服务于所有层面的 即plication fr

9、amework: 提供了 bean的配置基础,AOPtJ支持,JDBC勺提取框 架,抽象事务支持等等。 它有一个非常显著的特点: 在某个层面上如果你不需要 Spring 的支持,你就可以不使用 Spring 的 class ,只使用它的某一部分的功能。从它的设计理念,你可以看到 Spring 帮助你实现了真正的逻辑层和 web 层的分 离。例如:一个校验应用将不用依靠 controllers 就可以实现。 这样的目标更好 的重用 和易测 , 过分依靠不必要的容器和框架将不能实现这一点。当然,Spring有自己的web支持和通常框架模式细致完整。然而, Spring 替换struts、webwo

10、rk或者其他的web方案非常容易。对于 Spring的web支持或者 不同的地方,Spring允许你在web容器里面建立一个中间层,在测试环境或者标准独立的应用里面来设置重用你的商务逻辑?还有在J2EE环境里面,你的商务逻辑不必依靠容器提供的服务,像JTA ,EJB的支持。良好的构架的web应 用可以运行在任何容器上,如, Tomcat 或者 Resin 。值得注意的是, Spring 不 是和 已经存在的解决方案进行竞争 . 我们鼓励结合标准的技术, 如, Servlet,JSP, JTA,JNDI,JDBCa nd JDO和非常匹配的工具,如, Hibernate, Velocity, L

11、og4J, and CauchosHessian/Burlap 。这个框架的的设计思想是在你的应用需要改良 的时候, 你将会做一些技术的选择,例如 , 如果你需要分布式事务处理,你可能 需要用 Spring 的 Jta TransactionManager 来实现 JTA 服务。或者用 DataSource TransactionManager or HibernateTransactionManager 来实现的单个数据库交 换。Spring 框架通过配置操作mappings, 展示 resolution, 本地化和模版集成 围绕着分派请求操作的servlet-DispatcherServl

12、et设计的。缺省的操作是一个非常简单的控制接口 , 他只提供了 ModelAndView handleRequest (request, response) 方法。这将用于一个应用的控制 , 但是 , 如果你想包含多个层次的控制, AbstractController,AbstractCommandController,MultiActionController,SimpleFormController,AbstractWizardFormControll er将帮助你完成. 应用控制将代表那些子系统。注意,你可以选择一个适当的基类 : 如果你没有 webform, 你就不必用 FormCon

13、troller ,这就是和 Struts 最大的 不同。 你可以通过命令或者form 对象来操作任何对象,这不需要接口工具或者一个基础类的驱动。 Spring 的数据绑定非常灵活。举例来说, 它描述了具有在应 用范围内的校验错误的输入机制 , 但不是系统错误,所以在你的 form 对象里面你 不必复制你 的业务对象的 spring 属性 , 只操作出错的子任务, 或者适当地转换spring 。换句话说 , 它通常可以很好的直接绑定你的业务对象。 这也是和 struts 围绕请求基础 类 Action 和 ActionForm ( 每个 action 操作类型 ) 建立主要的不 同之一。对 比W

14、ebWork,Sping更多的区别在于对象角色:Spring支持控制器的感 念,一个操作命 令或者 form 对象和得到数据传递给视图的模式, 这个模式通常包 含命令和 form 对象 , 但有时也包含任意的参考数据。换句话说, 一个 WebWork Action 联合所有这些角色到一个单独的对象。WebWorl允许你用已经存在的业务 对象作为你form的一部分)但是只生成各自Action的bean属性。最后,操作请求的Action 实例在一个视 图里面获得付值和 form population 。然而 , 参考数据 也需要作为 Action 的属性 被模拟。 关于视图 : Spring 的视

15、图方案非常的灵活。一个控制器执行可以通过 response返回ModelAndView对象null就可以直接写到一个视图里,在一般情况下)一个ModelAndView实例结合了一个 view和一个 model Map,包含了 bean name和通讯 对象 (像命令或者form, 参考数据等等) 。 View 名称是非常高端的配置,不是通过bean name, 个properties 文件就是通过你自己的 ViewResolver. 这个抽象的model Map 允许你在视图层面完成提取, 没有任何的争辩JSP/Velocity 或者其他 ,每一种都可以直接完整使用 . 这个 model Ma

16、p 还可以简 单得得到适当的格式化数据 的转换,像JSP请求属性或者Velocity 模版模式.如果你不想用Spring的web MVC且是想借用Spring嫁接其他的解决方案 , 你可 以非常简单地通过Spring 继承你自己的 web 框架, 你可以非常简单地通过ContextLoaderListener 启动一个Spring root application context,并且, 通过 Struts 或者 WebWork的 action 利用 ServletContext 属性(或者 Spring的helper 方法)存取它。值得注意的是, 这里没有任何的 plugins 被调用 ,

17、因此没有专门的集成:来自web层的视图,你可以简单的将Spring作为一个管理 即plication context 实例入口点的类库。所有你注册bean 和 Spring 服务都可以在不需要Spring的webMVCl情况下都可以轻松掌握。Spring不是和Struts 、WebWo这些应用进行竞争,它将作为一个纯web框架应用于很多领域,因为它不需要配置数据存储和事务操作,所以,你可以利用 Spring 提供的中间层和数据存储层来丰富你的应用,甚至用JDBC者Hibernate进行事务抽象。如果仅仅聚焦于web支持,Spring的一些显著特点是清楚分离 :con troller,valid

18、ator,comma nd object,form object,model object,和DispatcherServlet,handler mapping vs view resolver等等强大而且直接的框架和作为JavaBeans的应用配置,包括简单的参照和应用内容,例如,从web控 制器到业务对象和数据校验。适应性 , 无论什么样的控制器你都需要得到代替Action/ActionForm 所做的每件事情的方案 ( 简单 , 命令 ,form, 范例 , 多重 action, 或 者定制一个) 重用业务逻辑代码, 不需要复制 , 你可以用已经有的业务逻辑对象作为命令或则 form 对

19、象代替反射特定的 ActionForm 子类。可订制的绑定和数据校验作为应用级的输入机制的错误校验, 固定日期和数字绑定, 例如 , 通过手动 检查和转换业务对象来替换单个的 string 。可订制的操作, 可订制的视图方案: 通过name/value Map 灵活的模型传送, 用一个简单的方法从简单到复杂操作映射和视图方案策略。 以在J2EE应用中非常普遍的用户登录过程为例来说明上述体系结构是如何具体运用的。登录的流程非常清晰:用户从登录页面 login.jsp 输入登录信息, 系统对 登录信息进行验证, 如果正确则成功登录, 否则提示相应错误信息。 在开 发过程 中,使用 Eclipse

20、做为开发环境,同时加载了对Struts 、 Spring 及 Hibernate 提供更好的控制和支持的第三方插件 MyEclipse , Web艮务器使用Tomcat,数据库 选用了 Mysql 。首先对 Hibernate 进行配置,只需要对系统自动生成的 hibernate.cfg.xml 进行修改 , 配置好数据库连接的各种参数以及定义数据映射文件。由于Hibernate 所带的连接池主要用于测试,性能不是很好,可以通过JNDI 将其修改为使用 Tomcat 的连接池。A Development Frame Application Based on the Hibernate、the

21、Struts and the Spring J2EEOne preface along with the Java technique of gradual mature and perfect. Be establishment business enterprise class application of standardterrace,the J2 EE terrace got substantial of development .Several technique asked for help from to include in the J2 EEnorm : Enterpris

22、e JavaBean (EJB), Java Servlets (Servlet), Java Server Pages(JSP), Java MessageService(JMS)etc., development manyapplication system.But, also appeared some problem in the tradition J2 the EE the application of the development the process:1)the antinomy of of data model and logic model. Currently the

23、 database of usage basically and all is relation type database, but the Java be essentially a kind of the language which face to object, object at saving with read usage SQL and JDBC carry on a database operation and lowered plait distance of efficiency and system of can maintenance;2)tradition of J

24、2 EE application much the adoption is according to the EJBheavy weight frame, this kind of frame suitable for develop a large business enterprise application, but usage the EJB container carry on development and adjust to try to need to be waste a great deal of time.For lowering the Ou of code to ma

25、tch sex, exaltation system of development efficiency, this text put forward one kind EE according to the J2 of the Struts frame 、 the Hibernate frame and the Spring frame application development strategy.The Hibernate FrameDatas holding out for long time layer and Hibernate is one piece according to

26、 hold out for long time layer frame, is a kind of realization object and relation of the tool which reflect to shoot(O/R Mapping), it carried on the object of the lightweight to pack to the JDBC and make procedure member can usage object plait distance thought to operation database. It not only prov

27、ided to shoot from Java to reflect of data form, but also provided a data a search and instauration mechanism. Opposite in usage JDBC and SQL to operation database, use Hibernate ability consumedly of exaltation realization of efficiency. The Hibernate frame use allocation document of the form come

28、to the reflect of the definition Java object and data form to shoot relation, in the meantime at more deep of level of data form of relation explanation for the relations such as inherit of and containment etc. of Java object. Pass the usage HQLlanguage sentence complications of relation the calcula

29、te way use the way of object description, to a large extent simplification logarithms according to of search, speed development of efficiency. Have in the Hibernate a simple but keep the API of view, used for to the database mean of object performance search. Want to establish or the modification be

30、 these objects, need in the procedure carry on with them to hand over with each other, then tell Hibernate to keep. So, a great deal of pack hold out for long time turn operation of business logic no longer demand write a trivial JDBC language sentence, make data last long thus the layer got biggest

31、 of simplification.Use the Struts realization MVCstructure MVC(Model-View-Controller) is put forward by the Trygve Reenskaug, first drive application in the environment SmallTalk-80, is many to hand over with each other with interface system of constitute foundation. According to the need of variabl

32、e of the interface design, MVChand over with each other constitute of system to resolve into model and see diagram, controller three part. Model(Model) is software processing problem logic at independence in outside manifestation under contents and form circumstance of inside abstract, packed the co

33、re data, logic of problem and function of calculation relation, independence in concrete of interface expression and I/O operation. See diagram(View) meaninformation and particular formdemonstration of model data and logic relation and appearance to thecustomer. It acquire a manifestation informatio

34、n from the model, there can be many for homology of information dissimilarity of manifestation form or see diagram. The controller(Controller) is a processing the customer hand over with software with each other operation of, its job is control provide model in any variety of dissemination, insure a

35、 customer interface amongthe model of rightness should contact; It accept a customer of importation, give the importation feedback model, thenrealization compute model control, is make model and see diagram to moderate work of parts. Usually 1 see a diagram rightness should a controller. Model, see

36、separate of diagram and controller, make a model be able to have many manifestation to see diagram. If the customer pass a certain see the controller of diagram change the data of model, all other dependence in these see of data diagram all should reflection arrive these variety. When therefore and

37、regardless occurrence what data variety, controller all would variety notice ally see diagram, cause manifestation of renewal. This is actually a kind of variety of model-dissemination mechanism.The Struts FrameThe Struts frame is to be the item of Apache Jakarta to constitute part to publish luck t

38、o do at the earliest stage, it inherited MVCof each item characteristic, and did according to the characteristics of J2 EE correspond of variety with expand. The Struts frame was good to combine Jsp , Java Servlet , Java Bean, Talia etc. technique. In the Struts, what to undertake the controller rol

39、e in the MVC be an ActionServlet. The ActionServlet is an in general use control module. This control module provided a processing all HTTP claim which send out Struts of entrance point. Its interception with distribute these claim to arrive correspond of action type.(these action all of type is Act

40、ion son type)Moreover the control module is also responsible for using to correspond of claim the parameter fill Action Form(FromBean), and pass action type(ActionBean).Action type the business logic of the interview core, then interview Java Bean or adjust to use EJB. End action type control the po

41、wer pass follow-up of JSP document, from JSP document born see diagram. All these control logic make use of Struts-config.xml the document come to allocation. See diagram in the Struts frame main from JSP born page completion, the Struts provide abundant of JSP label database, this is advantageous t

42、o separating performance logic and procedure logic.The model is with 1 or the form existence of several Java Bean. In the Struts, main existence three kinds of Bean, respectively BE: Action, ActionForm, EJB perhaps Java Bean. The Struts frame have no concrete definition model layer of realization, i

43、n actually the development, model layer usually is close with business logic connect with each other, and want to carry on operation to the first floor data. The underneaths introduction is a kind of development strategy, lead the Hibernate into the model layer of Struts frame, usage it to carry on

44、a data to pack with reflect to shoot, provide hold out for long time turn of support. 4 usage Hibernate and the Struts development J2 EEapplication 4.1 system structure diagram 3 manifestation according to Hibernate and Struts development strategy of system structure diagram.the Spring FrameSpring i

45、snt particularly a web framework but a generic lightweight application framework with dedicated web support, and show the architectural differences to Struts and WebWorkIn contrast to Struts or WebWork,Spring is an application framework for all layers: It offers a bean configuration foundation, AOP

46、support, JDBCabstraction framework, abstract transaction support etc. It is a very non-intrusive effort: Your application classes do not need to depend on any Spring classes if not necessary, and you can reuse every part on its own if you like to. From its very design, the frameworkencourages cleanseparation of tiers, most importantly web tier and business logic. e.g: the validation framework does not depend on web controllers. Major goals are reusability and testability: Unnecessary container or

温馨提示

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

评论

0/150

提交评论