版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选优质文档-倾情为你奉上J2EE文献及翻译1 引言本文分析了Hibernate和Struts的机制,提出了一种基于Hibernate和Struts的J2EE应用开发策略。在这种策略中,模型层用Hibernate实现,视图和控制器则用Struts框架实现。这样可大大降低代码的耦合性以及提高系统的开发效率。 关键字 Hibernate,Struts,MVC,持久层。 随着Java技术的逐渐成熟与完善,作为建立企业级应用的标准平台,J2EE平台得到了长足的发展。借助于J2EE规范中包含的多项技术:EnterpriseJavaBean(EJB)、Java Servlets(Servlet)、Java
2、 Server Pages(JSP)、Java Message Service(JMS)等,开发出了许多应用系统。但是,在传统J2EE应用的开发过程中也出现了一些问题:1)数据模型和逻辑模型之间的矛盾。目前使用的数据库基本上都是关系型数据库,而Java本质上是一种面向对象的语言,对象在存储和读取时使用SQL和JDBC进行数据库操作,降低了编程的效率以及系统的可维护性;2)传统的J2EE应用多采用基于EJB的重量级框架,这种框架适合于开发大型企业应用,但是使用EJB容器进行开发和调试需要耗费大量时间。为了降低代码的耦合性,提高系统的开发效率,本文提出了一种基于Struts框架和Hibernate
3、框架的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。ActionServlet
7、是一个通用的控制组件。这个控制组件提供了处理所有发送到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的连接池。附件:外文资料原文J2EE1 IntroductionThis text analysis the mech
10、anism 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 Struts frame a realization.So can consumedly lo
11、wer 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 enterprise class application of standard terr
12、ace, 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 system.But, also appeared some problem in the
13、 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 to object, object at saving with read usage SQ
14、L 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 business enterprise application, but usage the
15、 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 frame and the Hibernate frame application develop
16、ment 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), it carried on the object of the lightweig
17、ht 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 and SQL to operation database, use a Hib
18、ernate 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 relation explanation for the relations su
19、ch 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 efficiency.Have in the Hibernate a simple
20、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 pack hold out for long time turn operati
21、on 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 drive application in the environment Small
22、Talk-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 part. Model(Model) is software processing
23、 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.See diagram(View) mean information and part
24、icular 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(Controller) is a processing the customer ha
25、nd 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 model, then realization compute model
26、 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 the controller of diagram change th
27、e 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 actually a kind of variety of model-
28、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 expand.The Struts frame was good t
29、o 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 send out Struts of entrance point.Its
30、 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 type(ActionBean).Action type the busin
31、ess 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.See diagram in the Struts frame ma
32、in 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 Bean, respectively BE:Action, Acti
33、onForm, 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 underneath's introduction is a
34、 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 structure diagram 3 manifestation according to Hibernate and Struts development strategy of system structure diagram. Development pract
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 浅谈“双减”背景下三年级英语作业设计有效性的策略
- 《水电站》重点笔记
- SZSD 0067-2024智慧社区 老年人智能助餐场景设计指南
- 海口-PEP-2024年11版小学三年级下册英语第六单元真题
- 物质推断与转化(专项训练)-2023年中考化学二轮复习(原卷版)
- 2024年民宿旅游项目资金申请报告代可行性研究报告
- 强迫对流管簇管外放热系数测定实验
- 【沪科】期末模拟卷【九年级上下册】
- 护士聘岗个人工作总结范文(3篇)
- 读书伴我行演讲稿(35篇)
- 【仁爱】七上地理知识点总结
- 第四单元达标练习(单元练习)2024-2025学年统编版语文一年级上册
- 期中综合测试 2024-2025学年牛津译林版八年级英语上册
- 2025届山东省部分地区高三语文上学期期初试题汇编:写作专题
- TCECA-G 0304-2024 数字化碳管理平台 总体框架
- 2024-2030年云网融合行业市场发展分析及发展趋势与投资前景研究报告
- 2024-2025学年全国中学生天文知识竞赛考试题库(含答案)
- 2024-2025年新教材高中生物 第3章 第2节 第2课时 细胞器之间的协调配合和生物膜系统教案 新人教版必修1
- TSDPIA 03-2023 宠物猫砂生产质量安全管理规范
- 企业灭火和应急疏散应急预案
- 慕课《如何写好科研论文》期末考试答案
评论
0/150
提交评论