关于J2EE外文献翻译.doc

上传人:仙人指路1688 文档编号:2324901 上传时间:2023-02-11 格式:DOC 页数:7 大小:37.50KB
返回 下载 相关 举报
关于J2EE外文献翻译.doc_第1页
第1页 / 共7页
关于J2EE外文献翻译.doc_第2页
第2页 / 共7页
关于J2EE外文献翻译.doc_第3页
第3页 / 共7页
关于J2EE外文献翻译.doc_第4页
第4页 / 共7页
关于J2EE外文献翻译.doc_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《关于J2EE外文献翻译.doc》由会员分享,可在线阅读,更多相关《关于J2EE外文献翻译.doc(7页珍藏版)》请在三一办公上搜索。

1、J2EE开源技术应用规范 Andrew Glover1 引言本文分析了Hibernate和Struts的机制,提出了一种基于Hibernate和Struts的J2EE应用开发策略。在这种策略中,模型层用Hibernate实现,视图和控制器则用Struts框架实现。这样可大大降低代码的耦合性以及提高系统的开发效率。 关键字 Hibernate,Struts,MVC,持久层。 随着Java技术的逐渐成熟与完善,作为建立企业级应用的标准平台,J2EE平台得到了长足的发展。借助于J2EE规范中包含的多项技术:EnterpriseJavaBean(EJB)、Java Servlets(Servlet)、

2、Java Server Pages(JSP)、Java Message Service(JMS)等,开发出了许多应用系统。但是,在传统J2EE应用的开发过程中也出现了一些问题:1)数据模型和逻辑模型之间的矛盾。目前使用的数据库基本上都是关系型数据库,而Java本质上是一种面向对象的语言,对象在存储和读取时使用SQL和JDBC进行数据库操作,降低了编程的效率以及系统的可维护性;2)传统的J2EE应用多采用基于EJB的重量级框架,这种框架适合于开发大型企业应用,但是使用EJB容器进行开发和调试需要耗费大量时间。为了降低代码的耦合性,提高系统的开发效率,本文提出了一种基于Struts框架和Hiber

3、nate框架的J2EE应用开发策略。2 J2EE开源技术介绍数据持久层及Hibernate,Hibernate是一个数据持久层框架,是一种实现对象和关系之间映射(O/R Mapping)的工具,它对JDBC进行了轻量级的对象封装,使程序员可以使用对象编程思想来操作数据库。它不仅提供了从Java类到数据表的映射,也提供了数据查询和恢复机制。相对于使用JDBC和SQL来操作数据库,使用Hibernate能大大的提高实现的效率。Hibernate框架用配置文件的形式来定义Java对象和数据表之间的映射关系,同时在更深的层面将数据表之间的关系解释为Java对象之间的继承及包含等关系。通过使用HQL语句

4、将复杂的关系算法用对象的方式描述,在很大程度上简化了对数据的查询,加快了开发的效率。在Hibernate中有一个简单而直观的API,用于对数据库所表示的对象执行查询。要创建或修改这些对象,只需在程序中与它们进行交互,然后告诉Hibernate保存即可。这样,大量封装持久化操作的业务逻辑不再需要编写烦琐的JDBC语句,从而使数据持久层得到了极大的简化。 用Struts实现MVC架构 MVC(Model-View-Controller)由Trygve Reenskaug提出,首先被应用在SmallTalk-80环境中,是许多交互和界面系统的构成基础。根据界面设计可变性的需求,MVC把交互系统的组成

5、分解成模型、视图、控制器三部分。 模型(Model)是软件所处理问题逻辑在独立于外在显示内容和形式情况下的内在抽象,封装了问题的核心数据、逻辑和功能的计算关系,独立于具体的界面表达和I/O操作。视图(View)把表示模型数据及逻辑关系和状态的信息及特定形式展示给用户。它从模型获得显示信息,对于相同的信息可以有多个不同的显示形式或视图。控制器(Controller)是处理用户与软件的交互操作的,其职责是控制提供模型中任何变化的传播,确保用户界面于模型间的对应联系;它接受用户的输入,将输入反馈给模型,进而实现对模型的计算控制,是使模型和视图协调工作的部件。通常一个视图对应一个控制器。模型、视图与控

6、制器的分离,使得一个模型可以具有多个显示视图。如果用户通过某个视图的控制器改变了模型的数据,所有其它依赖于这些数据的视图都应反映到这些变化。因此,无论何时发生了何种数据变化,控制器都会将变化通知所有的视图,导致显示的更新。这实际上是一种模型的变化-传播机制。 Struts框架最早是作为Apache Jakarta项目的组成部分问世运做,它继承了MVC的各项特性,并根据J2EE的特点,做了相应的变化与扩展。Struts框架很好的结合了Jsp,Java Servlet,Java Bean,Taglib等技术。在Struts中,承担MVC中控制器角色的是ActionServlet。ActionSer

7、vlet是一个通用的控制组件。这个控制组件提供了处理所有发送到Struts的HTTP请求的入口点。它截取和 分发这些请求到相应的动作类(这些动作类都是Action类的子类)。另外控制组件也负责用相应的请求参数填充Action Form(FromBean),并传给动作类(ActionBean)。动作类访问核心商业逻辑,即访问Java Bean或调用EJB。最后动作类把控制权传给后续的JSP文件,由JSP文件生成视图。所有这些控制逻辑利用Struts-config.xml文件来配置。在Struts框架中,视图主要由JSP生成页面完成,Struts提供丰富的JSP标签库,这有利于分开表现逻辑和程序逻

8、辑。模型以一个或多个Java Bean的形式存在。在Struts中,主要存在三种Bean,分别是:Action,ActionForm,EJB或者Java Bean。 Struts框架没有具体定义模型层的实现,在实际开发中,模型层通常是和业务逻辑紧密相连的,并且要对底层数据进行操作。下面介绍一种开发策略,将Hibernate引入到Struts框架的模型层中,使用它来进行数据封装和映射,提供持久化的支持。 下面结合开发实践,以在J2EE应用中非常普遍的用户登录过程为例,来说明上述体系结构是如何具体运用的。登录的流程非常清晰:用户从登录页面login.jsp输入登录信息,系统对登录信息进行验证,如果

9、正确则成功登录,否则提示相应错误信息。 在开发过程中,使用Eclipse做为开发环境,同时加载了对Struts及Hibernate提供更好的控制和支持的第三方插件MyEclipse,Web服务器使用Tomcat,数据库选用了Mysql。 首先对Hibernate进行配置,只需要对系统自动生成的hibernate.cfg.xml进行修改,配置好数据库连接的各种参数以及定义数据映射文件。由于Hibernate所带的连接池主要用于测试,性能不是很好,可以通过JNDI将其修改为使用Tomcat的连接池。附件:外文资料原文Application Specification of J2EEAndrew G

10、lover1 IntroductionThis text analysis the mechanism of Hibernate and Struts, put forward 1 kind EE according to the J2 of the Hibernate and the Struts application development strategy.In this kind of strategy, the model layer use a Hibernate realization and see diagram and controller to then use a S

11、truts frame a realization.So can consumedly lower the development efficiency that the Ou of code match sex and exaltation system. The key word Hibernate, Struts, the MVC, hold out for long time a layer one preface along with the Java technique of gradual mature and perfect, Be establishment business

12、 enterprise class application of standard terrace, the J2EE terrace got substantial of development.Several technique asked for help from to include in the J2 EE norm:Enterprise JavaBean(EJB), Java Servlets(Servlet), Java Server Pages(JSP), Java Message Service(JMS).etc., development many application

13、 system.But, also appeared some problem in the tradition J2 the EE the application of the development the process: the antinomy of of data model and logic model.Currently the database of usage basically and all is relation type database, but the Java be essentially a kind of the language which face

14、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; tradition of J2 EE application much the adoption is according to the EJB heavy weight frame, this kind of frame suitable for develop a large

15、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 Out of code to match sex, exaltation system of development efficiency, this text put forward 1 kind EE according to the J2EE of the Struts fra

16、me and the Hibernate frame application development strategy.2 Open Source Technology of J2EEDatas holding out for long time layer and Hibernate is one piece according to 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),

17、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 provided to shoot from Java to reflect of data form, but also provided a data a search and instauration mechanism.Opposite in usage JDBC

18、 and SQL to operation database, use a Hibernate ability consumedly of exaltation realization of efficiency.The Hibernate frame use allocation document of the form come 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

19、relation explanation for the relations such as inherit of and containment etc. of Java object.Pass the usage HQL language sentence complications of relation the calculate way use the way of object description, to a large extent simplification logarithms according to of search, speed development of e

20、fficiency.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 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

21、 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 of simplification. Use the Struts realization MVC structure MVC(Model-View-Controller) is put forward by the Trygve Reenskaug, first d

22、rive 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 variable of the interface design, MVC hand over with each other constitute of system to resolve into model and see diagram, controller three

23、part. Model(Model) is software processing problem logic at independence in outside manifestation under contents and form circumstance of inside abstract, packed the core data, logic of problem and function of calculation relation, independence in concrete of interface expression and I/O operation.Se

24、e diagram(View) mean information and particular form demonstration of model data and logic relation and appearance to the customer.It acquire a manifestation information from the model, there can be many for homology of information dissimilarity of manifestation form or see diagram.The controller(Co

25、ntroller) 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 customer interface among the model of rightness should contact;It accept a customer of importation, give the importation feedback mo

26、del, then realization 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 separate of diagram and controller, make a model be able to have many manifestation to see diagram.If the customer pass a certain see

27、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 regardless occurrence what data variety, controller all would variety notice allly see diagram, cause manifestation of renewal.This is a

28、ctually a kind of variety of model-dissemination mechanism. The Struts frame is to be the item of Apache Jakarta to constitute part to publish luck to do at the earliest stage, it inheritted MVC of each item characteristic, and did according to the characteristics of J2 EE correspond of variety with

29、 expand.The Struts frame was good to combine Jsp, Java Servlet, Java Bean, Taglib etc. technique.In the Struts, what to undertake the controller role 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 se

30、nd out Struts of entrance point.Its interception with distribute these claim to arrive correspond of action type.(these action all of type is Action son type)Moreover the control module is also responsible for using to correspond of claim the parameter fill Action Form(FromBean), and pass action typ

31、e(ActionBean).Action type the business logic of the interview core, then interview Java Bean or adjust to use EJB.End action type control the power 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

32、.See diagram in the Struts frame main from JSP born page completion, the Struts provide abundant of JSP label database, this is advantageous to 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

33、 Bean, respectively BE:Action, ActionForm, EJB perhaps Java Bean. The Struts frame have no concrete definition model layer of realization, in 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

34、 underneaths introduction is a kind of development strategy, lead the Hibernate into the model layer of Struts frame, usage it to carry on 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 EE application 4.1 system s

35、tructure diagram 3 manifestation according to Hibernate and Struts development strategy of system structure diagram. Development practice underneath combine a development practice, with in the J2 the EE the application very widespread customer register process for example, elucidation above-mentione

36、d system structure is how concrete usage.The process of register is very clear:Customer from register page login.jsp importation register information, system to register the information carry on verification, if exactitude success register, otherwise hint correspond mistake information. In the devel

37、opment process, the usage Eclipse be used as development environment and added to carry to provide to the Struts and the Hibernate in the meantime better control and support of three square plug-in MyEclipse, Web server usage Tomcat, the database chose to use Mysql. Carry on an allocation to the Hib

38、ernate first, need to the system auto the born hibernate.cfg.xml carry on modification, allocation good database conjunction of various parameter and definition the data reflect to shoot a document.Because the Hibernate take of conjunction pond main used for test, the function isnt very good, can pass JNDI will it modification is usage Tomcat of conjunction pond.

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

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


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号