2023年全國碩士研究生考試考研英語一試題真題(含答案詳解+作文范文)_第1頁
已閱讀1頁,還剩15頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、<p>  JSP application frameworks</p><p>  What are application frameworks:</p><p>  A framework is a reusable, semi-complete application that can be specialized to</p><p>  pro

2、duce custom applications [Johnson]. Like people, software applications are more alike than they are different. They run on the same computers, expect input from the same devices, output to the same displays, and save dat

3、a to the same hard disks. Developers working on conventional desktop applications are accustomed to toolkits and development environments that leverage the sameness between applications. Application frameworks build on t

4、his common ground to provide developers with a reusable s</p><p>  A framework provides developers with a set of backbone components that have the following characteristics:</p><p>  1.They are

5、known to work well in other applications.</p><p>  2. They are ready to use with the next project.</p><p>  3. They can also be used by other teams in the organization.</p><p>  Fra

6、meworks are the classic build-versus-buy proposition. If you build it, you will understand it when you are done—but how long will it be before you can roll your own? If you buy it, you will have to climb the learning cur

7、ve—and how long is that going to take? There is no right answer here, but most observers would agree that frameworks such as Struts provide a significant return on investment compared to starting from scratch, especially

8、 for larger projects.</p><p>  Other types of frameworks:</p><p>  The idea of a framework applies not only to applications but to application componentsas well. Throughout this article, we intr

9、oduce other types of frameworks that you can use with Struts. These include the Lucene search engine, the Scaffold toolkit, the Struts validator, and the Tiles tag library. Like application frameworks, these tools provid

10、e semi-complete versions of a subsystem that can be specialized to provide a custom component.</p><p>  Some frameworks have been linked to a proprietary development environment. This is not the case with St

11、ruts or any of the other frameworks shown in this book. You can use any development environment with Struts: Visual Age for Java, JBuilder, Eclipse, Emacs, and Textpad are all popular choices among Struts developers. If

12、you can use it with Java, you can use it with Struts.</p><p>  Enabling technologies:</p><p>  Applications developed with Struts are based on a number of enabling technologies.These components

13、are not specific to Struts and underlie every Java web application. A reason that developers use frameworks like Struts is to hide the nasty details behind acronyms like HTTP, CGI, and JSP. As a Struts developer, you don

14、’t need to be an alphabet soup guru, but a working knowledge of these base technologies can help you devise creative solutions to tricky problems.</p><p>  Hypertext Transfer Protocol (HTTP):</p><

15、p>  When mediating talks between nations, diplomats often follow a formal protocol.</p><p>  Diplomatic protocols are designed to avoid misunderstandings and to keep negotiations from breaking down. In a

16、similar vein, when computers need to talk, they also follow a formal protocol. The protocol defines how data is transmitted and how to decode it once it arrives. Web applications use the Hypertext Transfer Protocol (HTTP

17、) to move data between the browser running on your computer and the application running on the server.</p><p>  Many server applications communicate using protocols other than HTTP. Some of these maintain an

18、 ongoing connection between the computers. The application server knows exactly who is connected at all times and can tell when a connection is dropped. Because they know the state of each connection and the identity of

19、each person using it, these are known as stateful protocols.</p><p>  By contrast, HTTP is known as a stateless protocol. An HTTP server will accept any request from any client and will always provide some t

20、ype of response, even if the response is just to say no. Without the overhead of negotiating and retaining a connection, stateless protocols can handle a large volume of requests. This is one reason why the Internet has

21、been able to scale to millions of computers.</p><p>  Another reason HTTP has become the universal standard is its simplicity. An HTTP request looks like an ordinary text document. This has made it easy for

22、applications to make HTTP requests. You can even send an HTTP request by hand using a standard utility such as Telnet. When the HTTP response comes back, it is also in plain text that developers can read.</p><

23、p>  The first line in the HTTP request contains the method, followed by the location</p><p>  of the requested resource and the version of HTTP. Zero or more HTTP request headers follow the initial line.

24、The HTTP headers provide additional information to the server. This can include the browser type and version, acceptable document types, and the browser’s cookies, just to name a few. Of the seven request methods, GET an

25、d POST are by far the most popular.</p><p>  Once the server has received and serviced the request, it will issue an HTTP response. The first line in the response is called the status line and carries the HT

26、TP protocol version, a numeric status, and a brief description of the status. Following the status line, the server will return a set of HTTP response headers that work in a way similar to the request headers.</p>

27、<p>  As we mentioned, HTTP does not preserve state information between requests.The server logs the request, sends the response, and goes blissfully on to the next request. While simple and efficient, a stateless

28、protocol is problematic for dynamic applications that need to keep track of their users. (Ignorance is not always bliss.</p><p>  Cookies and URL rewriting are two common ways to keep track of users between

29、requests. A cookie is a special packet of information on the user’s computer. URL rewriting stores a special reference in the page address that a Java server can use to track users. Neither approach is seamless, and usin

30、g either means extra work when developing a web application. On its own, a standard HTTP web server does not traffic in dynamic content. It mainly uses the request to locate a file and then returns that </p><p

31、>  Standard web servers handle static content and images quite well but need a helping hand to provide users with a customized, dynamic response. </p><p>  DEFINITION:Static content on the Web comes direc

32、tly from text or data files, like HTML or JPEG files. These files might be changed from time to time, but they are not altered automatically when requested by a web browser. Dynamic content, on the other hand, is generat

33、ed on the fly, typically in response to an individualized request from a browser.</p><p>  Common Gateway Interface (CGI):</p><p>  The first widely used standard for producing dynamic content w

34、as the Common Gateway Interface (CGI). CGI uses standard operating system features, such as environment variables and standard input and output, to create a bridge, or gateway, between the web server and other applicatio

35、ns on the host machine. The other applications can look at the request sent to them by the web server and create a customized response.</p><p>  When a web server receives a request that’s intended for a CGI

36、 program, it runs that program and provides the program with information from the incoming request. The CGI program runs and sends its output back to the server. The web server then relays the response to the browser.<

37、;/p><p>  CGI defines a set of conventions regarding what information it will pass as environment variables and how it expects standard input and output to be used. Like HTTP, CGI is flexible and easy to implem

38、ent, and a great number of CGI-aware programs have been written.</p><p>  The main drawback to CGI is that it must run a new copy of the CGI-aware program for each request. This is a relatively expensive pro

39、cess that can bog down high-volume sites where thousands of requests are serviced per minute. Another drawback is that CGI programs tend to be platform dependent. A CGI program written for one operating system may not ru

40、n on another.</p><p>  Java servlets:</p><p>  Sun’s Java Servlet platform directly addresses the two main drawbacks of CGI programs.First, servlets offer better performance and utilization of r

41、esources than conventional CGI programs. Second, the write-once, run-anywhere nature of Java means that servlets are portable between operating systems that have a Java Virtual Machine (JVM).</p><p>  A serv

42、let looks and feels like a miniature web server. It receives a request and renders a response. But, unlike conventional web servers, the servlet application programming interface (API) is specifically designed to help Ja

43、va developers create dynamic applications.</p><p>  The servlet itself is simply a Java class that has been compiled into byte code, like any other Java object. The servlet has access to a rich API of HTTP-s

44、pecific services, but it is still just another Java object running in an application and can leverage all your other Java assets.</p><p>  To give conventional web servers access to servlets, the servlets ar

45、e plugged into containers. The servlet container is attached to the web server. Each servlet can declare what URL patterns it would like to handle. When a request matching a registered pattern arrives, the web server pas

46、ses the request to the container, and the container invokes the servlet.</p><p>  But unlike CGI programs, a new servlet is not created for each request. Once the container instantiates the servlet, it will

47、just create a new thread for each request. Java threads are much less expensive than the server processes used by CGI programs. Once the servlet has been created, using it for additional requests incurs very little overh

48、ead. Servlet developers can use the init() method to hold references to expensive resources, such as database connections or EJB Home Interfaces, so that t</p><p>  The other edge of the sword is that, since

49、 servlets are multithreaded, servlet developers must take special care to be sure their servlets are thread-safe. To learn more about servlet programming, we recommend Java Servlets by Example, by Alan R. Williamson [Wil

50、liamson]. The definitive source for Servlet information is the Java Servlet Specification [Sun, JST].</p><p>  JavaServer Pages:</p><p>  While Java servlets are a big step up from CGI programs,

51、 they are not a panacea. To generate the response, developers are still stuck with using println statements to render the HTML. Code that looks like:</p><p>  out.println("<P>One line of HTML.<

52、/P>");</p><p>  out.println("<P>Another line of HTML.</P>");</p><p>  is all too common in servlets that generate the HTTP response. There are libraries that can he

53、lp you generate HTML, but as applications grow more complex, Java developers end up being cast into the role of HTML page designers.</p><p>  Meanwhile, given the choice, most project managers prefer to divi

54、de development teams into specialized groups. They like HTML designers to be working on the presentation while Java engineers sweat the business logic. Using servlets alone encourages mixing markup with business logic, m

55、aking it difficult for team members to specialize.</p><p>  To solve this problem, Sun turned to the idea of using server pages to combine scripting and templating technologies into a single component. To bu

56、ild Java Server Pages, developers start by creating HTML pages in the same old way, using the same old HTML syntax. To bring dynamic content into the page, the developer can also place JSP scripting elements on the page.

57、 Scripting elements are tags that encapsulate logic that is recognized by the JSP. You can easily pick out scripting elements on JSP </p><p>  To be seen as a JSP page, the file just needs to be saved with a

58、n extension of .jsp.</p><p>  When a client requests the JSP page, the container translates the page into a source code file for a Java servlet and compiles the source into a Java class file—just as you woul

59、d do if you were writing a servlet from scratch. At runtime, the container can also check the last modified date of the JSP file against the class file. If the JSP file has changed since it was last compiled, the contain

60、er will retranslate and rebuild the page all over again.</p><p>  Project managers can now assign the presentation layer to HTML developers, who then pass on their work to Java developers to complete the bus

61、iness-logic portion. The important thing to remember is that a JSP page is really just a servlet. Anything you can do with a servlet, you can do with a JSP.</p><p>  JavaBeans:</p><p>  JavaBean

62、s are Java classes which conform to a set of design patterns that make them easier to use with development tools and other components.</p><p>  DEFINITION A JavaBean is a reusable software component written

63、in Java. To qualify as a JavaBean, the class must be concrete and public, and have a noargument constructor. JavaBeans expose internal fields as properties by providing public methods that follow a consistent design patt

64、ern. Knowing that the property names follow this pattern, other Java classes are able to use introspection to discover and manipulate JavaBean properties. </p><p>  The JavaBean design patterns provide acces

65、s to the bean’s internal state through two flavors of methods: accessors are used to read a JavaBean’s state; mutators are used to change a JavaBean’s state.</p><p>  Mutators are always prefixed with lowerc

66、ase token set followed by the property name. The first character in the property name must be uppercase. The return value is always void—mutators only change property values; they do not retrieve them. The mutator for a

67、simple property takes only one parameter in its signature, which can be of any type. Mutators are often nicknamed setters after their prefix. The mutator method signature for a weight property of the type Double would be

68、:</p><p>  public void setWeight(Double weight)</p><p>  A similar design pattern is used to create the accessor method signature. Accessor methods are always prefixed with the lowercase token g

69、et, followed by the property name. The first character in the property name must be uppercase. The return value will match the method parameter in the corresponding mutator. Accessors for simple properties cannot accept

70、parameters in their method signature. Not surprisingly, accessors are often called getters.</p><p>  The accessor method signature for our weight property is:</p><p>  public Double getWeight()&

71、lt;/p><p>  If the accessor returns a logical value, there is a variant pattern. Instead of using the lowercase token get, a logical property can use the prefix is, followed by the property name. The first char

72、acter in the property name must be uppercase. The return value will always be a logical value—either boolean or Boolean. Logical accessors cannot accept parameters in their method signature.</p><p>  The boo

73、lean accessor method signature for an on property would be</p><p>  public boolean isOn()</p><p>  The canonical method signatures play an important role when working with Java- Beans. Other com

74、ponents are able to use the Java Reflection API to discover a JavaBean’s properties by looking for methods prefixed by set, is, or get. If a component finds such a signature on a JavaBean, it knows that the method can be

75、 used to access or change the bean’s properties.</p><p>  Sun introduced JavaBeans to work with GUI components, but they are now used with every aspect of Java development, including web applications. When S

76、un engineers developed the JSP tag extension classes, they designed them to work with JavaBeans. The dynamic data for a page can be passed as a JavaBean, and the JSP tag can then use the bean’s properties to customize th

77、e output.</p><p>  For more on JavaBeans, we highly recommend The Awesome Power of JavaBeans, by Lawrence H. Rodrigues [Rodrigues]. The definitive source for JavaBean information is the JavaBean Specificatio

78、n [Sun, JBS].</p><p><b>  Model 2:</b></p><p>  The 0.92 release of the Servlet/JSP Specification described Model 2 as an architecture that uses servlets and JSP pages together in th

79、e same application. The term Model 2 disappeared from later releases, but it remains in popular use among Java web developers.</p><p>  Under Model 2, servlets handle the data access and navigational flow, w

80、hile JSP pages handle the presentation. Model 2 lets Java engineers and HTML developers each work on their own part of the application. A change in one part of a Model 2 application does not mandate a change to another p

81、art of the application. HTML developers can often change the look and feel of an application without changing how the back-office servlets work.</p><p>  The Struts framework is based on the Model 2 architec

82、ture. It provides a controller servlet to handle the navigational flow and special classes to help with the data access. A substantial custom tag library is bundled with the framework to make Struts easy to use with JSP

83、pages.</p><p><b>  Summary:</b></p><p>  In this article, we introduced Struts as an application framework. We examined the technology behind HTTP, the Common Gateway Interface, Java

84、 servlets, JSPs, and JavaBeans. We also looked at the Model 2 application architecture to see how it is used to combine servlets and JSPs in the same application.</p><p>  Now that you have had a taste of wh

85、at it is like to develop a web application with Struts, in chapter 2 we dig deeper into the theory and practice behind the Struts architecture.</p><p><b>  JSP 應(yīng)用框架</b></p><p><b&

86、gt;  什么是應(yīng)用框架:</b></p><p>  框架(framework)是可重用的,半成品的應(yīng)用程序,可以用來產(chǎn)生專門的定制程序。象人一樣,軟件應(yīng)用的相似性比不同點要多。它們運行在相似的機器上,期望從相同的設(shè)備輸入信息,輸出到相同的顯示設(shè)備,并且將數(shù)據(jù)存儲到相同的硬盤設(shè)備。開發(fā)傳統(tǒng)桌面應(yīng)用的開發(fā)人員更習(xí)慣于那些可以涵蓋應(yīng)用開發(fā)同一性的工具包和開發(fā)環(huán)境。構(gòu)架在這些公共基礎(chǔ)上的應(yīng)用框架可以為開發(fā)

87、人員提供可以為他們的產(chǎn)品提供可重用服務(wù)的基礎(chǔ)架構(gòu)。</p><p>  框架向開發(fā)人員提供一系列具有以下特征的骨架組件:</p><p>  1.已經(jīng)知道它們在其它程序上工作得很好;</p><p>  2.它們隨時可以在下一個項目中使用;</p><p>  3.它們可以被組織的其它團(tuán)隊使用;</p><p>  對

88、于框架是典型的構(gòu)建還是購買命題。如果你自己構(gòu)建它,在你完成時你就會理解它,但是在你被融入之前又將花費多長時間呢?如果要購買,你必須得克服學(xué)習(xí)曲線,同樣,在你可以用它進(jìn)行工作之前又得花多長時間?這里沒有所謂正確答案,但許多觀察者都會同意,象Struts這樣的框架能提供比從頭開始開發(fā)更顯著的投資回報,特別是對于大型項目來說。</p><p><b>  其它類型的框架:</b></p>

89、;<p>  框架的概念不僅用于應(yīng)用程序也可用于組件。在其它的資料里面,我們也介紹了一些可以和Struts一起使用的框架。這些包括Lucene搜索引擎,Scaffold工具包,Struts驗證器,以及Tiles標(biāo)簽庫。與應(yīng)用框架一樣,這些工具也提供了一些半完成的版本,可以用在用戶的定制組件之中。某些框架被限制于專門的開發(fā)環(huán)境中。Struts以及本文中涉及的組件卻不是這樣。你可以在很多環(huán)境中來開發(fā)Struts: Visual

90、 Age for Java, JBuilder, Eclipse, Emacs, 甚至使用Textpad。對于你的工具,如果你可以用來開發(fā)Java, 你就可以用它來開發(fā)Struts。</p><p><b>  使用的技術(shù):</b></p><p>  使用Struts的應(yīng)用開發(fā)使用了大量的其他基礎(chǔ)技術(shù)。這些技術(shù)并不是專門針對Struts,而是所有Java web 應(yīng)

91、用都可以使用的。開發(fā)者使用Struts之類的框架是為了隱藏在諸如HTTP,CGI,以及JSP之類技術(shù)后面的繁瑣的細(xì)節(jié)。作為一個Struts開發(fā)者,你并不需要知曉所有的相關(guān)知識,但是這些基本技術(shù)的工作原理可能有助于你針對棘手問題設(shè)計出創(chuàng)造性的方案。</p><p>  超文本傳輸協(xié)議 (HTTP):</p><p>  當(dāng)兩個國家之間進(jìn)行調(diào)解時,外交官們總是遵循一定的正式協(xié)議。外交協(xié)議主要設(shè)

92、計來避免誤解,以及防止談判破裂。同樣,當(dāng)計算機間需要對話,它們也遵循一個正式的協(xié)議。這個協(xié)議定義數(shù)據(jù)是如何傳輸,以及它們到達(dá)后如何進(jìn)行解碼。Web應(yīng)用程序就是使用HTTP協(xié)議在運行瀏覽器的計算機和運行的服務(wù)器的程序間傳輸數(shù)據(jù)。</p><p>  很多服務(wù)器應(yīng)用程序使用HTTP之外的其他協(xié)議。他們在計算機之間維護(hù)一個持久性的連接。應(yīng)用服務(wù)器可以清楚的知道是誰連接上來,而且何時中斷連接。因為它們知道每一個連接的狀態(tài)

93、,以及每一個使用它的人。這稱之為狀態(tài)協(xié)議。</p><p>  相反, HTTP是一個無狀態(tài)協(xié)議。HTTP Server 可以接受來自于各種客戶的各種請求,并提供各種響應(yīng),即使是這個響應(yīng)僅僅是說No。沒有大量的協(xié)商和連接持久性,無狀態(tài)協(xié)議可以處理大量的請求。這也是Internet 可以擴展到很多計算機的原因。</p><p>  HTTP 成為通用標(biāo)準(zhǔn)的原因是其簡單性。HTTP請求看起來就

94、像一個平常的文本文檔。這使應(yīng)用程序很容易創(chuàng)建HTTP請求。你甚至可以通過標(biāo)準(zhǔn)的程序如Telnet來手動傳遞一個HTTP請求。當(dāng)HTTP響應(yīng)返回時,它也是一個開發(fā)者可以直接閱讀的平面文本。HTTP請求的第一行包含方法,其后是請求的來源地址和HTTP版本。HTTP請求頭跟在首行后面,可以沒有也可以有多個。HTTP頭向服務(wù)器提供額外的信息??梢园g覽器的種類和版本,可接受的文檔類型,瀏覽器的cookies等等。7 種請求方法中, GET和

95、POST是用得最多的。</p><p>  一旦服務(wù)器接收到請求,它就要產(chǎn)生一個HTTP響應(yīng)。響應(yīng)的第一行稱為狀態(tài)行,包含了HTTP協(xié)議的版本,數(shù)字型狀態(tài),以及狀態(tài)的簡短描述。狀態(tài)行后,服務(wù)器將返回一個HTTP響應(yīng)頭,類似于HTTP請求頭。如上所述,HTTP并不在請求間保持狀態(tài)信息。服務(wù)器接受請求,發(fā)出響應(yīng),并且繼續(xù)愉快地處理文本請求。</p><p>  因為簡單和效率,無狀態(tài)協(xié)議不適合

96、于需要跟蹤用戶狀態(tài)的動態(tài)應(yīng)用。Cookies和 URL 重寫是兩個在請求間跟蹤用戶狀態(tài)的方式。cookie是一種特殊的信息包,存儲于用戶的計算機中。URL重寫是在頁面地址中存儲一個特殊的標(biāo)記,Java服務(wù)器可以用它來跟蹤用戶。這兩種方法都不是無縫的,是用哪一個都意味著在開發(fā)時都要進(jìn)行額外的工作。對其本身來說,標(biāo)準(zhǔn)的HTTP web服務(wù)器并不傳輸動態(tài)內(nèi)容。它主要是使用請求來定位文件資源,并在響應(yīng)中返回此資源。通常這里的文件使用Hypert

97、ext Markup Language (HTML) [W3C,HTML] 格式化,以使瀏覽器可以顯示它們。HTML頁面通常包含一些到其他頁面的超文本連接,也可以顯示其他一些內(nèi)容比如圖像和視頻等等。用戶點擊連接將產(chǎn)生另一個請求,就開始一個新的處理過程。標(biāo)準(zhǔn)web服務(wù)器處理靜態(tài)內(nèi)容處理得很好,但處理動態(tài)內(nèi)容時則需要額外的幫助手段了。</p><p>  定義 靜態(tài)內(nèi)容直接來自于文本或數(shù)據(jù)文件,比如HTML或者 JP

98、EG文件。這些文件可以隨時改變,但通過瀏覽器請求時,卻不能自動改變。相反,動態(tài)內(nèi)容是臨時產(chǎn)生的,典型地,它是針對瀏覽器的個別請求的響應(yīng)。</p><p>  公共網(wǎng)關(guān)接口(CGI):</p><p>  第一個普遍用來產(chǎn)生動態(tài)內(nèi)容的標(biāo)準(zhǔn)是通用網(wǎng)關(guān)接口(Common Gateway Interface (CGI))。CGI使用標(biāo)準(zhǔn)的操作系統(tǒng)特征,比如環(huán)境變量和標(biāo)準(zhǔn)輸入輸出,在Web服務(wù)器間以

99、及和主機系統(tǒng)間創(chuàng)建橋接和網(wǎng)關(guān)。其他程序可以看到web server傳遞過來的請求,并創(chuàng)建一個定制的響應(yīng)。當(dāng)web服務(wù)器接收到一個對CGI程序的請求時,它便運行這個程序并向其提供它請求里面所包含的信息。CGI程序運行,并將輸出返回給Web server,web server 則將輸出響應(yīng)給瀏覽器。CGI定義了一套關(guān)于什么信息將作為環(huán)境變量傳遞,以及它希望怎樣使用標(biāo)準(zhǔn)輸入和輸出的慣例。與HTTP一樣,CGI是靈活和易于實現(xiàn)的,并且已經(jīng)有大量

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論