




已阅读5页,还剩25页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
毕业设计外文资料翻译(译文)译文题目: 深入struts架构 原文题目: exploring the struts architecture 原文出处: struts kick start exploring the struts architecturethis chapter covers_ introducing application frameworks, mvc, and model 2_ understanding how struts works_ using the struts control flow_ exploring the strengths and weaknesses of struts2.1 talking the talkthis chapter explores the struts framework in depth and highlights the benefits struts can bring to your development efforts. we believe that once you can “talk the talk” of web architecture and design, you will be better equipped to use struts with your own applications.with a sound overview of the struts architecture in place, we outline the struts control flow and the way it handles the request-response event cycle. a good understanding of this process makes it much easier to create applications that make the best use of the framework.choosing a web application framework should not be a casual decision. many people will use this book, and especially this chapter, as part of evaluating struts for their project. accordingly, we conclude this chapter with a candid look at the strengths and weaknesses of the struts framework and address concerns regarding overall performance. struts is designed for professional developers. to make informed decisions, professionals need to be aware of both a tools capabilities and its limitations.2.2 why we need strutstodays web applications are critical components of the corporate mission. as always, development teams need to build applications in record time, but they have to build them right and build them to last.java web developers already have utilities for building presentation pages, such as java server pages and velocity templates. we also have mechanisms for handling databasesjdbc and enterprise javabeans (ejbs), for example. but what do we use to put these components together? we have the plumbing and the drywall what else do we need?2.2.1 one step back, three steps forwardin the late 1970s, when graphical user interfaces (guis) were being invented, software architects saw applications as having three major parts: the part that manages data, the part that creates screens and reports, and the part that handles interactions between the user and the other subsystems ooram. in the early1980s, the objectworks/smalltalk programming environment introduced this triumvirate as a development framework. in smalltalk 80 parlance, the data system is dubbed the model, the presentation system is called the view, and the interaction system is the controller. many modern development environments, including javas swing, use this model/view/controller (mvc) architecture (see figure 2.1) as the foundation of their own frameworks.java web developers already have capable tools, such as jdbc and jsp, for consulting the model and creating the view, but wheres the controller for our web applications?2.2.2 enter strutsthe centerpiece of struts is an mvc-style controller. the struts controller bridges the gap between model and view. the framework also includes other missing pieces developers need to write scalable, leading-edge web applications. struts is a collection of “invisible underpinnings” that help developers turn raw materials like databases and web pages into a coherent application.2.2.3 struts controller componentsthe struts controller is a set of programmable components that allow developers to define exactly how their application interacts with the user. these components view controllermodel figure 2.1 the model/view/controller architecture hide nasty, cumbersome implementation details behind logical names. developers can program these details once, then go back to thinking in terms of what the program does rather than how it does it.users interact with a web application through hyperlinks and html forms. the hyperlinks lead to pages that display data and other elements, such as text and images. the forms generally submit data to the application via some type of custom action. as shown in figure 2.2, struts provides components that programmers can use to define the hyperlinks, forms, and custom actions that web applications use to interact with the user. we used these components to build a starter application in chapter 1. in chapter 3, we walk through using these components to build another simple application. then, in chapter 4, we provide a detailed overview of configuring these components. later chapters provide more detail about putting each component to use within your application. in part 4 we demonstrate using the components in the context of working applications. but, since this chapter is the architectural overview, lets go ahead and introduce the major struts components now.note :the struts components are configured via xml. in practice, the configuration elements are an integral part of the struts framework. to help you put it all together, we show a sample of each components xml element as it is introduced.hyperlinksto the application developer, a hyperlink is a path to some resource in the application.this may be a web page or a custom action. it may also include special parameters. in struts, developers can define a hyperlink as an actionforward.these objects have a logical name and a path property. this lets developers set the path and then refer to the actionforward by name.actionforwards are usually defined in an xml configuration file that struts reads when the web application loads. struts uses the xml definitions to create the hyperlinks/actionforms html forms/actionforms custom actions/actionforms figure struts configuration, which includes a list of actionforwards. the xml element that would create an actionforward for a welcome hyperlink might look like this:this element would create an actionform javabean with its name property set to welcome and its path property set to /pages/index.jsp.jsp pages and other components can then refer to the welcome forward. the struts framework will look up the welcome actionforward bean and retrieve the path to complete the hyperlink. this allows developers to change the destination of a link without changing all the components that refer to that link. in most web applications, details like this are hardcoded into jsp and java code, making changes difficult and prone to error. in a struts application, these details can be changed throughout the application without touching a single page or java class.for more about actionforwards, see chapter 6.html formsthe web protocols, http and html, provide a mechanism for submitting data from a form but leave receiving the data as an exercise for the developer. the struts framework provides an actionform class, which is designed to handle input from an html form, validate the input, and redisplay the form to the user for correction(when needed), along with any corresponding prompts or messages.actionforms are just javabeans with a couple of standard methods to manage the validation and revision cycle. struts automatically matches the javabean properties with the attributes of the html controls. the developer defines the actionform class. struts does the rest.this class will automatically populate the username field from a form with an html form element of the same name, as shown here:public final class logonform extends actionform private string username = null;public string getusername() return (this.username);public void setusername(string username) this.username = username;other properties would be added for each field of the form. this lets other componentsget what they need from a standard javabean, so everyone does not haveto sift through an http request.the actionform classes are created using normal java classes. the struts configuration refers to the actionform classes through a set of descriptors: the and elements. the elements are descriptors that the framework uses to identify and instantiate the actionform objects,as shown here:the struts configuration lists the actionform beans it uses and gives the actionform classes a logical name to use within the application.1.0 vs 1.1 in struts 1.1 the actionform can also use a map (java.util.map) to store the attribute names rather than define individual properties. a new type of javabean, the dynabean, can also be used with struts 1.1 and later.you can specify the properties for a dynaactionform by using an xml element.in effect, this does let you define actionforms in the struts configuration file.for more about actionforms, see chapter 5.custom actionsan html form uses an action parameter to tell the browser where to send the forms data. the struts framework supplies a corresponding action class to receive such data. the framework automatically creates, populates, validates, and finally passes the appropriate actionform to the action object. the action can then get the data it needs directly from the actionform bean. heres an example:public final class logonaction extends action public actionforward perform(actionmapping mapping,actionform form,httpservletrequest request,httpservletresponse response)throws ioexception, servletexception myform myform = (myform) form;/ .return mapping.findforward(continue);an action concludes by returning an actionforward object to the controller. this allows the action to choose a definition using logical names, like continue or cancel, rather than system paths.to ensure extensibility, the controller also passes the current request and response object. in practice, an action can do anything a java servlet can do.1.0 vs 1.1 in struts 1.1 a new execute method is preferred over the perform method shown in our example. the perform method is deprecated but supported for backward compatibility. the execute method signature allows for better exception handling. the new exceptionhandler is covered in chapter 9.for more about action objects, see chapter 8.in addition to the actionforward, actionform, and action objects,the struts controller layer provides several other specialized components, including actionmappings and the actionservlet. struts also supports localizing your application from the controller layer.actionmappingsin a web application, every resource must be referred to through a uniform resource identifier (uri). this includes html pages, jsp pages, and any custom actions. to give the custom actions a uri, or path, the struts framework provides an actionmapping object. like the actionforwards and actionforms, the mappings are usually defined in the xml configuration file:this also allows the same action object to be used by different mappings. for example, one mapping may require validation; another may not.for more about actionmappings, see chapter 7.actionservletthe struts actionservlet works quietly behind the scenes, binding the other components together. although it can be subclassed, most struts 1.0 developers treat the actionservlet as a blackbox: they configure it and leave it alone. for more about configuring struts, see chapter 4.in struts 1.1, the actionservlet is easier to extend. chapter 9 covers the new extension points and configuration options for the struts 1.1 actionservlet.localizationweb applications also interact with users through prompts and messages. the struts components have localization features built in so that applications can be written for an international audience. we refer to the localization features throughout the book. a general overview is provided in chapter developing a web application with strutsto build a web application with struts, developers will define the hyperlinks they need as actionforwards, the html forms they need as actionforms, and whatever custom server-side actions they need as action classes.developers who need to access ejbs or jdbc databases can do so by way of the action object. this way, the presentation page does not need to interact with themodel layer.the struts action object will collect whatever data a view may need and then forward it to the presentation page. struts provides a jsp tag library for use with jsp pages that simplifies writing html forms and accessing other data that an action may forward. other presentation devices, such as velocity templates, can also access the struts framework to create dynamic web pages. this process is shown in figure 2.3.for more about using various data systems with struts, see chapter 14. see chapters 10 and 11 to learn more about creating presentation pages with struts.before moving deeper into the struts architecture, lets take a look at the issues faced by a web application framework that the architecture must address.2.3 why we need frameworksin chapter 1, we introduced application frameworks and briefly discussed why frameworks are important. but to really understand a solution, you need to appreciate the problem. developing for the web, while rewarding, brings its own set of challenges. lets take a quick look at what makes web development so challenging.2.3.1 the weba never-ending klugeweb developers are hampered by a double web whammy. first, we are expected to use web browsers for clients. second, we must use the web protocol to communicate.web browsers communicate via hypertext transmission protocol (http) and display pages created with hypertext markup language (html). a web browser sends out the http request and renders the html it receives in response. this is an excellent platform for serving prewritten pages that rarely change. but most of us are writing dynamic applications with pages that are customized for each user. while there are some handy “hooks” for dynamic features, web applications go against the http/html grain.as shown in table 2.1, restrictions imposed by the web protocol and the web clients predetermine how web applications can be written. table 2.1 difficulties web applications face and web application frameworks must addressrestrictions imposed byresult in these difficultiesthe protocolby default, http will accept a connection from any client on the network.changing this behavior varies from server to server.primarily, http transfers data using simple text fields. transferring binary data requires use of a complicated extension to the protocol.http is sessionless and requires extra effort to track people using the application.http is trusting and expects that clients will provide accurate information.the clientsbrowsers are separate applications outside the applications direct control.all browsers are not equal and support different subsets of the official standards.input from a browser may be incorrect or incomplete. input may even be hostile and contrived to harm the application.the standard web formatting language, html, cannot construct many of the interface elements found in desktop environments.creating html controls with default data is an exercise left to the pplication.sadly, the situation is not going to change any time soon. web developers must see these shortcomings as challenges to overcome. since there are so many obstacles to writing robust web applications, using a framework is vital, lest your application become an endless series of workarounds and kluges.the challenges we face when developing web applications are great. but so are the rewards. the duo of the http protocol and the html client makes web applications accessible to people the world over. no other platform has ever been able to make that claim.2.3.2 the servlet solutionas mentioned in chapter 1, the java servlet platform sun, jst acts like a base framework to provide java web applications with a number of important capabilities. the servlet class provides a base interface for handling http requests and the ensuing response. it builds on http to provide a “session” context to help track users in the application. it provides other contexts to help applications pass data to the browsers or to other servlets in the application. java web applications also have uniform access to basic security features that would otherwise be managed differently by different http servers.to put this all together, the servlet specification describes a container to manage the servlets. the container may also provide other services, such as a handler for jsps. a servlet container can include its own web server or simply act as an adjunct to an existing web server.for database access, java applications have another common framework at their disposal: jdbc. developers can write to a standard sql interface while an adapter takes care of the hoary details. this makes it easier to change database vendors without rewriting the source code.for high-performance applications that access database systems on remote servers, web developers can use the enterprise javabean platform. most java application frameworks, including struts, can be used with ejbs when they are needed. overall, this makes web applications based on java servlets very portable and relatively easy to write and maintain. servlets and jsps have made a real difference in the way we write applications. java web application frameworks like struts build on the servlet platform and try to provide developers with a seamless, kluge-free environment.2.3.3 servlet frameworksmost, if not all, java web frameworks use the sun servlet platform as a
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 责任与个人幸福
- 谈判心理学知识培训课程课件
- 2025标识标牌智能导视系统设计与集成合同范本
- 2025版互联网平台委托管理合同示范文本
- 2025版全新大包工程合同含绿色施工技术创新条款下载
- 2025年度创业团队合伙人竞业禁止合同范本
- 2025版办公楼墙面翻新美化与节能改造合同
- 2025年材料合同终止与供应链优化协议
- 2025年度智能环保节能建筑项目施工工程合同台账模板
- 2025版乳胶漆施工安全教育与培训合同协议书
- 浙教版数学七年级上册全册优质课件
- 220kV××输电线路工程预算实例
- 空间向量及其线性运算课件 高二上学期数学人教A版(2019)选择性必修第一册
- 俄罗斯历史与文化课件
- 3.4 商品质量品级评定与质量监督
- 一年级谁比谁多练习题(比较实用)
- 金矿汇报实用教案课件
- 个案分析-万科四季花城
- 年轻人群酒水消费洞察报告
- 社会化媒体全套教学课件
- 幼儿园绘本:《你真好》 PPT课件
评论
0/150
提交评论