毕业设计论文 外文文献翻译 深入Struts架构 中英文对照.doc

上传人:laozhun 文档编号:4027233 上传时间:2023-04-01 格式:DOC 页数:31 大小:747KB
返回 下载 相关 举报
毕业设计论文 外文文献翻译 深入Struts架构 中英文对照.doc_第1页
第1页 / 共31页
毕业设计论文 外文文献翻译 深入Struts架构 中英文对照.doc_第2页
第2页 / 共31页
毕业设计论文 外文文献翻译 深入Struts架构 中英文对照.doc_第3页
第3页 / 共31页
毕业设计论文 外文文献翻译 深入Struts架构 中英文对照.doc_第4页
第4页 / 共31页
毕业设计论文 外文文献翻译 深入Struts架构 中英文对照.doc_第5页
第5页 / 共31页
点击查看更多>>
资源描述

《毕业设计论文 外文文献翻译 深入Struts架构 中英文对照.doc》由会员分享,可在线阅读,更多相关《毕业设计论文 外文文献翻译 深入Struts架构 中英文对照.doc(31页珍藏版)》请在三一办公上搜索。

1、毕业设计外文资料翻译(译文)译文题目: 深入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 weakne

2、sses 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 applica

3、tions.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 applica

4、tion 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

5、 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 tea

6、ms 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 JavaB

7、eans (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 havin

8、g 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 framew

9、ork. 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 foundat

10、ion 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 t

11、he 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

12、 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

13、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, s

14、uch 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 thes

15、e 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 u

16、se 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 co

17、nfiguration 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

18、 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 configur

19、ation 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

20、 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 Actio

21、nForward 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

22、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

23、 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 Ja

24、vaBeans 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 f

25、ield 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 add

26、ed 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 desc

27、riptors: 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 Str

28、uts 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, thi

29、s 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 fram

30、ework 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(ActionMappin

31、g 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

32、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

33、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 Acti

34、onForward, 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 r

35、eferred 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

36、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 componen

37、ts 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 con

38、figuration 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 t

39、hroughout the book. A general overview is provided in chapter 13.2.2.4 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 t

40、hey 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 presenta

41、tion 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

42、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 arch

43、itecture 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. L

44、ets 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 T

45、ransmission 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 applic

46、ations 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.

47、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 usin

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

当前位置:首页 > 办公文档 > 其他范文


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号