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

下載本文檔

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

文檔簡(jiǎn)介

1、<p>  JSP APPLICATION FRAMEWORKS</p><p>  1.1 WHAT ARE APPLICATION FRAMEWORKS:</p><p>  A framework is a reusable, semi-complete application that can be specialized to produce custom applic

2、ations [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 data to the same hard

3、 disks. Developers working on conventional desktop applications are accustomed to toolkits and development environments that leverage the sameness between applications. Applicatio</p><p>  A framework provid

4、es developers with a set of backbone components that have the following characteristics:</p><p>  Frameworks are the classic build-versus-buy proposition. If you build it, you will understand it when you are

5、 done—but how long will it be before you can roll your own? If you buy it, you will have to climb the learning curve—and how long is that going to take? There is no right answer here, but most observers would agree that

6、frameworks such as Struts provide a significant return on investment compared to starting from scratch, especially for larger projects.</p><p>  1.2 OTHER TYPES OF FRAMEWORKS:</p><p>  The idea

7、of a framework applies not only to applications but to application components as well. Throughout this article, we introduce other types of frameworks that you can use with Struts. These include the Lucene search engine,

8、 the Scaffold toolkit, the Struts validator, and the Tiles tag library. Like application frameworks, these tools provide semi-complete versions of a subsystem that can be specialized to provide a custom component.</p&

9、gt;<p>  Some frameworks have been linked to a proprietary development environment. This is not the case with Struts or any of the other frameworks shown in this book. You can use any development environment with

10、Struts: Visual Age for Java, JBuilder, Eclipse, Emacs, and Textpad are all popular choices among Struts developers. If you can use it with Java, you can use it with Struts.</p><p>  1.3 ENABLING TECHNOLPGIES

11、:</p><p>  Applications developed with Struts are based on a number of enabling technologies. These components are not specific to Struts and underlie every Java web application. A reason that developers use

12、 frameworks like Struts is to hide the nasty details behind acronyms like HTTP, CGI, and JSP. As a Struts developer, you don’t need to be an alphabet soup guru, but a working knowledge of these base technologies can help

13、 you devise creative solutions to tricky problems.</p><p>  1.4 HYPERTEXT TRANSFER PROTOCOL (HTTP):</p><p>  When mediating talks between nations, diplomats often follow a formal protocol.</p

14、><p>  Diplomatic protocols are designed to avoid misunderstandings and to keep negotiations from breaking down. In a similar vein, when computers need to talk, they also follow a formal protocol. The protocol

15、defines how data is transmitted and how to decode it once it arrives. Web applications use the Hypertext Transfer Protocol (HTTP) to move data between the browser running on your computer and the application running on t

16、he server.</p><p>  Many server applications communicate using protocols other than HTTP. Some of these maintain an ongoing connection between the computers. The application server knows exactly who is conne

17、cted at all times and can tell when a connection is dropped. Because they know the state of each connection and the identity of each person using it, these are known as stateful protocols.</p><p>  By contra

18、st, HTTP is known as a stateless protocol. An HTTP server will accept any request from any client and will always provide some type of response, even if the response is just to say no. Without the overhead of negotiating

19、 and retaining a connection, stateless protocols can handle a large volume of requests. This is one reason why the Internet has been able to scale to millions of computers.</p><p>  Another reason HTTP has b

20、ecome the universal standard is its simplicity. An HTTP request looks like an ordinary text document. This has made it easy for applications to make HTTP requests. You can even send an HTTP request by hand using a standa

21、rd utility such as Telnet. When the HTTP response comes back, it is also in plain text that developers can read.</p><p>  The first line in the HTTP request contains the method, followed by the location of t

22、he requested resource and the version of HTTP. Zero or more HTTP request headers follow the initial line. The HTTP headers provide additional information to the server. This can include the browser type and version, acce

23、ptable document types, and the browser’s cookies, just to name a few. Of the seven request methods, GET and POST are by far the most popular.</p><p>  Once the server has received and serviced the request, i

24、t will issue an HTTP response. The first line in the response is called the status line and carries the HTTP protocol version, a numeric status, and a brief description of the status. Following the status line, the serve

25、r will return a set of HTTP response headers that work in a way similar to the request headers.</p><p>  As we mentioned, HTTP does not preserve state information between requests. The server logs the reques

26、t, sends the response, and goes blissfully on to the next request. While simple and efficient, a stateless protocol is problematic for dynamic applications that need to keep track of their users.</p><p>  Co

27、okies and URL rewriting are two common ways to keep track of users between 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

28、 Java server can use to track users. Both approaches are seamless, and using either means extra work when developing a web application. On its own, a standard HTTP web server does not traffic in dynamic content. It mainl

29、y uses the request to locate a file and then returns that </p><p>  Standard web servers handle static content and images quite well but need a helping hand to provide users with a customized, dynamic respon

30、se. </p><p>  DEFINITION: Static content on the Web comes directly 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 whe

31、n requested by a web browser. Dynamic content, on the other hand, is generated on the fly, typically in response to an individualized request from a browser.</p><p>  1.5 COMMON GATEWAY INTERFACE (CGI):</

32、p><p>  The first widely used standard for producing dynamic content was the Common Gateway Interface (CGI). CGI uses standard operating system features, such as environment variables and standard input and out

33、put, to create a bridge, or gateway, between the web server and other applications on the host machine. The other applications can look at the request sent to them by the web server and create a customized response.</

34、p><p>  When a web server receives a request that’s intended for a CGI program, it runs that program and provides the program with information from the incoming request. The CGI program runs and sends its outpu

35、t back to the server. The web server then relays the response to the browser.</p><p>  CGI defines a set of conventions regarding what information it will pass as environment variables and how it expects sta

36、ndard input and output to be used. Like HTTP, CGI is flexible and easy to implement, 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 co

37、py of the CGI-aware program for each request. This is a relatively expensive process that can bog down high-volume sites where thousands of requests are serviced per minute. Another drawback is that CGI programs tend to

38、be platform dependent. A CGI program written for one operating system may not run on another.</p><p>  1.6 JAVA SERVLETS:</p><p>  Sun’s Java Servlet platform directly addresses the two main dra

39、wbacks of CGI programs. First, servlets offer better performance and utilization of resources than conventional CGI programs. Second, the write-once, run-anywhere nature of Java means that servlets are portable between o

40、perating systems that have a Java Virtual Machine (JVM).</p><p>  A Servlet looks and feels like a miniature web server. It receives a request and renders a response. But, unlike conventional web servers, th

41、e Servlet application programming interface (API) is specifically designed to help Java developers create dynamic applications.</p><p>  The Servlet itself is simply a Java class that has been compiled into

42、byte code, like any other Java object. The Servlet has access to a rich API of HTTP-specific services, but it is still just another Java object running in an application and can leverage all your other Java assets.</p

43、><p>  To give conventional web servers access to servlets, the servlets are plugged into containers. The Servlet container is attached to the web server. Each Servlet can declare what URL patterns it would lik

44、e to handle. When a request matching a registered pattern arrives, the web server passes the request to the container, and the container invokes the Servlet.</p><p>  But unlike CGI programs, a new Servlet i

45、s not created for each request. Once the container instantiates the Servlet, it will just create a new thread for each request. Java threads are much less expensive than the server processes used by CGI programs. Once th

46、e Servlet has been created, using it for additional requests incurs very little overhead. Servlet developers can use the init () method to hold references to expensive resources, such as database connections or EJB Home

47、Interfaces, so that </p><p>  The other edge of the sword is that, since servlets are multithreaded, Servlet developers must take special care to be sure their servlets are thread-safe. </p><p>

48、  1.7 JAVASERVER PAGES:</p><p>  While Java servlets are a big step up from CGI programs, they are not a panacea. To generate the response, developers are still stuck with using println statements to render

49、the HTML. Code that looks like:</p><p>  out.println("<P>One line of HTML.</P>");</p><p>  out.println("<P>Another line of HTML.</P>");</p><

50、;p>  It is all too common in servlets that generate the HTTP response. There are libraries that can help you generate HTML, but as applications grow more complex, Java developers end up being cast into the role of HTM

51、L page designers. Meanwhile, given the choice, most project managers prefer to divide development teams into specialized groups. They like HTML designers to be working on the presentation while Java engineers sweat the b

52、usiness logic. Using servlets alone encourages mixing markup with bu</p><p>  To solve this problem, Sun turned to the idea of using server pages to combine scripting and templating technologies into a singl

53、e component. To build 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 ele

54、ments on the page. 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

55、to be saved with an 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

56、—just as you would 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 comp

57、iled, the container 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

58、 complete the business-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>  1.8 JAVABEANS:</p>

59、<p>  JavaBeans 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 softw

60、are component written in Java. To qualify as a JavaBean, the class must be concrete and public, and have a non-argument constructor. JavaBeans expose internal fields as properties by providing public methods that follow

61、a consistent design pattern. 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 desig

62、n patterns provide access 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 alw

63、ays prefixed with lowercase 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

64、them. The mutator for a simple property takes only one parameter in its signature, which can be of any type. Mutators are often nicknamed setters after their prefix. </p><p>  The mutator method signature fo

65、r a weight property of the type Double would be:</p><p>  public void setWeight(Double weight);</p><p>  A similar design pattern is used to create the accessor method signature. Accessor method

66、s are always prefixed with the lowercase token get, 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

67、. Accessors for simple properties cannot accept parameters in their method signature. Not surprisingly, accessors are often called getters.</p><p>  The accessor method signature for our weight property is:&

68、lt;/p><p>  public Double getWeight();</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

69、is, followed by the property name. The first character 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 thei

70、r method signature.</p><p>  The boolean accessor method signature for an on property would be:</p><p>  public boolean isOn();</p><p>  The canonical method signatures play an impo

71、rtant role when working with Java- Beans. Other components 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 signa

72、ture on a JavaBean, it knows that the method can be 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 J

73、ava development, including web applications. When Sun 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

74、 can then use the bean’s properties to customize the output.</p><p>  Resource: http://book.huihoo.com/pdf/introduction-to-machine-learning/JSP 應(yīng)用框架</p><p>  1.1 什么是應(yīng)用框架:</p><p>  框

75、架(framework)是可以被重用的一種半成品的應(yīng)用程序,我們可以用它來(lái)制作專(zhuān)門(mén)的定制程序。這就如同人類(lèi)一樣,軟件應(yīng)用的相同點(diǎn)要遠(yuǎn)遠(yuǎn)大于不同點(diǎn)。它們?cè)谙嗤臋C(jī)器上運(yùn)行,把信息輸入相同的設(shè)備,用相同的顯示設(shè)備顯示,并將數(shù)據(jù)村存儲(chǔ)到相同的硬件設(shè)備中。傳統(tǒng)的桌面開(kāi)發(fā)應(yīng)用的開(kāi)發(fā)人員更習(xí)慣于使用可以涵蓋應(yīng)用開(kāi)發(fā)同一性的工具包和開(kāi)發(fā)環(huán)境??蚣芴峁┙o開(kāi)發(fā)人員這些公共基礎(chǔ)上的應(yīng)用框架從而為他們的產(chǎn)品提供可重用服務(wù)的基本架構(gòu)。</p>&

76、lt;p>  框架是經(jīng)典的構(gòu)建-購(gòu)買(mǎi)-命題。如果你獨(dú)立構(gòu)建它——那當(dāng)你可以獨(dú)立完成的時(shí)候你就會(huì)理解它,但是你又花費(fèi)了多長(zhǎng)時(shí)間來(lái)用之自如呢?如果你購(gòu)買(mǎi)了它,你必須得克服學(xué)習(xí)曲線——并且學(xué)習(xí)它將話費(fèi)你大約多長(zhǎng)時(shí)間?這里沒(méi)有明確的答案,因此許多專(zhuān)家會(huì)認(rèn)為,例如Struts這樣的框架能提供比全新的開(kāi)發(fā)更顯著的投資回報(bào),特別是對(duì)大型項(xiàng)目來(lái)說(shuō)尤為顯著。</p><p>  1.2 其它類(lèi)型的框架:</p>

77、<p>  框架的思想不僅僅用于應(yīng)用程序也可以應(yīng)用于組件。通過(guò)這些,我們以前也提到過(guò)一些可以與在Struts一起使用的框架。其中包括Lucene搜索引擎,Scaffold工具包,Struts驗(yàn)證器,以及Tiles標(biāo)簽庫(kù)等等。就像應(yīng)用框架一樣,這些工具也提供了一些可以用在用戶(hù)的定制組件之中的半成品。</p><p>  某些框架已經(jīng)唄限定于專(zhuān)門(mén)的開(kāi)發(fā)環(huán)境之中。而Struts以及本文中涉及的其他框架卻不是

78、這樣的。你可以在各種各樣的開(kāi)發(fā)環(huán)境中來(lái)使用Struts:例如Visual Age for Java, JBuilder, Eclipse, Emacs, 甚至在Textpad中都可以使用Struts。只要是可以用來(lái)開(kāi)發(fā)Java的工具都可以用來(lái)開(kāi)發(fā)Struts。</p><p>  1.3 使用的技術(shù):</p><p>  使用Struts的應(yīng)用開(kāi)發(fā)基于大量的其它技術(shù)。這些技術(shù)并不專(zhuān)屬于St

79、ruts而是針對(duì)所有Java web 應(yīng)用的。開(kāi)發(fā)人員之所以使用Struts之類(lèi)的框架的一個(gè)原因是為了隱藏在HTTP,CGI,以及JSP之類(lèi)技術(shù)后面的繁瑣細(xì)節(jié)。作為一個(gè)Struts開(kāi)發(fā)人員,你并不需要完全了解Struts的所有相關(guān)知識(shí),但是它們有助于解決比較麻煩的問(wèn)題。</p><p>  1.4 超文本傳輸協(xié)議 (HTTP) :</p><p>  當(dāng)兩個(gè)國(guó)家質(zhì)檢進(jìn)行交涉時(shí),外交官們總是

80、遵循一定的正式協(xié)議。</p><p>  設(shè)計(jì)外交協(xié)議的主要目的是避免誤會(huì)從而防止談判破裂。同樣,當(dāng)兩臺(tái)計(jì)算機(jī)需要進(jìn)行會(huì)話時(shí),它們也要遵循一個(gè)正式協(xié)議。這個(gè)協(xié)議定義數(shù)據(jù)如何傳輸以及到達(dá)后如何進(jìn)行解碼。Web應(yīng)用程序使用HTTP協(xié)議從而在運(yùn)行瀏覽器的計(jì)算機(jī)和運(yùn)行的服務(wù)器的程序之間傳輸數(shù)據(jù)。</p><p>  很多服務(wù)器應(yīng)用程序使用HTTP之外的其他協(xié)議。這些協(xié)議中的大多數(shù)是計(jì)算機(jī)之間的持久

81、性連接。應(yīng)用服務(wù)器可以清楚的知道是誰(shuí)什么時(shí)候連接的并截止到何時(shí)中斷的連接。因?yàn)樗鼈冎烂恳粋€(gè)連接的狀態(tài)甚至每一個(gè)使用它的人,這就是所謂的狀態(tài)協(xié)議。</p><p>  與此相反,HTTP被認(rèn)為是一個(gè)無(wú)狀態(tài)協(xié)議。HTTP Server 可以接受來(lái)自于各種客戶(hù)的各種請(qǐng)求并且可以提供一些響應(yīng),即使這個(gè)響應(yīng)僅僅是一個(gè)No。沒(méi)有大量的協(xié)議和連接持久性,無(wú)狀態(tài)協(xié)議可以處理大量的請(qǐng)求。這就是Internet可以被數(shù)量如此巨大的

82、計(jì)算機(jī)使用的原因之一。</p><p>  HTTP 成為通用標(biāo)準(zhǔn)的原因之一是簡(jiǎn)單性。一個(gè)HTTP請(qǐng)求看起來(lái)就像一個(gè)平常的文本文檔。這使應(yīng)用程序創(chuàng)建HTTP請(qǐng)求變得相當(dāng)容易。你甚至可以通過(guò)標(biāo)準(zhǔn)的程序比如說(shuō)Telnet來(lái)手動(dòng)發(fā)送HTTP請(qǐng)求。當(dāng)HTTP響應(yīng)返回時(shí),開(kāi)發(fā)人員也可以直接在文本文檔中讀到其中的內(nèi)容。</p><p>  HTTP請(qǐng)求的首行包含方法,其后是請(qǐng)求的來(lái)源地址和HTTP版本

83、??梢詻](méi)有也可以有多個(gè)。HTTP頭向服務(wù)器提供額外的信息。可以包括瀏覽器的類(lèi)型和版本,可接受的文檔類(lèi)型,瀏覽器的cookies,僅僅為了一個(gè)名等等。在這7 種請(qǐng)求方法中, GET和 POST是最流行的。</p><p>  當(dāng)服務(wù)器接收到請(qǐng)求,服務(wù)器會(huì)馬上產(chǎn)生一個(gè)HTTP響應(yīng)。響應(yīng)的首行稱(chēng)為狀態(tài)行包含了HTTP協(xié)議的版本,字符型狀態(tài),以及該狀態(tài)的簡(jiǎn)短描述。緊隨狀態(tài)行其后,服務(wù)器將返回一組類(lèi)似于HTTP請(qǐng)求頭的HT

84、TP響應(yīng)頭。</p><p>  按我們所描述的,HTTP并不會(huì)在請(qǐng)求之間保留狀態(tài)信息。服務(wù)器接受請(qǐng)求,發(fā)出響應(yīng),并且順利的處理文本請(qǐng)求。盡管HTTP是簡(jiǎn)單與快捷的,但是無(wú)狀態(tài)的HTTP協(xié)議并不適合于需要跟蹤用戶(hù)狀態(tài)的動(dòng)態(tài)應(yīng)用。</p><p>  Cookies和 URL 重寫(xiě)是兩種應(yīng)用于請(qǐng)求之間跟蹤用戶(hù)狀態(tài)的方式。cookie是一種用戶(hù)電腦上的特殊信息包。URL重寫(xiě)是在頁(yè)面地址中存儲(chǔ)一

85、個(gè)特殊的標(biāo)記從而讓Java服務(wù)器可以用它來(lái)跟蹤用戶(hù)。這兩種方法都不是完美的,而且使用哪一個(gè)都意味著開(kāi)發(fā)web工程時(shí)需要進(jìn)行額外的工作。對(duì)其本身來(lái)說(shuō),標(biāo)準(zhǔn)的HTTP web服務(wù)器并不需要發(fā)送動(dòng)態(tài)內(nèi)容。它主要是使用請(qǐng)求來(lái)定位并在相應(yīng)中返回文件資源。通常這里的文件使用超文本語(yǔ)言 (HTML) [W3C,HTML] 格式化以及顯示它們。HTML頁(yè)面通常包含一些到其他頁(yè)面的超連接,或者說(shuō)一些其他內(nèi)容比如圖片視頻等等。用戶(hù)點(diǎn)擊鏈接產(chǎn)生一個(gè)新的請(qǐng)求,

86、同時(shí)開(kāi)始了一個(gè)新的處理過(guò)程。</p><p>  標(biāo)準(zhǔn)web服務(wù)器對(duì)于靜態(tài)內(nèi)容和圖片的處理相當(dāng)好,但處理動(dòng)態(tài)內(nèi)容時(shí)需要外力的幫助。</p><p>  定義:web中的靜態(tài)內(nèi)容直接來(lái)自于文本或數(shù)據(jù)文件,例如HTML或JPEG文件。這些文件可以隨時(shí)改變,但通過(guò)瀏覽器請(qǐng)求時(shí)卻不能自動(dòng)改變。相反,從另一方面來(lái)說(shuō),動(dòng)態(tài)內(nèi)容是臨時(shí)產(chǎn)生的,它是針對(duì)瀏覽器的一個(gè)典型的個(gè)別請(qǐng)求的響應(yīng)。</p>

87、<p>  1.5 公共網(wǎng)關(guān)接口(CGI) :</p><p>  首個(gè)廣泛使用動(dòng)態(tài)內(nèi)容的標(biāo)準(zhǔn)是通用網(wǎng)關(guān)接口Common Gateway Interface (CGI)。CGI使用環(huán)境變量,標(biāo)準(zhǔn)的輸入輸出等標(biāo)準(zhǔn)的操作系統(tǒng)特征,在Web服務(wù)器之間,以及和主機(jī)系統(tǒng)之間創(chuàng)建橋接和網(wǎng)關(guān)。其他應(yīng)用可以看到web server傳遞過(guò)來(lái)的請(qǐng)求并創(chuàng)建一個(gè)定制的響應(yīng)。</p><p>  當(dāng)一

88、個(gè)web服務(wù)器收到一個(gè)對(duì)CGI程序的請(qǐng)求時(shí),服務(wù)器運(yùn)行CGI程序并向CGI提供它請(qǐng)求里面所包含的信息。CGI程序開(kāi)始運(yùn)行后將輸出返回給web 服務(wù)器。web服務(wù)器把相應(yīng)發(fā)送給瀏覽器。</p><p>  CGI定義了一套關(guān)于什么信息將作為環(huán)境變量傳遞以及它希望如何使用標(biāo)準(zhǔn)的輸入輸出。就像HTTP一樣,CGI是靈活和易于實(shí)現(xiàn)的,并且已經(jīng)有大量成型的CGI程序。</p><p>  CGI程序

89、的主要缺點(diǎn)是每個(gè)請(qǐng)求對(duì)應(yīng)一個(gè)新副本。這是一個(gè)相對(duì)昂貴的處理方法對(duì)大容量站點(diǎn)來(lái)說(shuō)每分鐘的數(shù)千個(gè)請(qǐng)求可能會(huì)使站點(diǎn)癱瘓。另一個(gè)缺點(diǎn)是依賴(lài)于平臺(tái)。為一個(gè)操作系統(tǒng)寫(xiě)的CGI不能在其他操作系統(tǒng)上使用。</p><p>  1.6 Java servlet:</p><p>  Sun公司的Java Servlet平臺(tái)直接解決了CGI程序的兩個(gè)主要缺點(diǎn)。首先servlet 比CGI 程序提供更好的性能和

90、資源利用。其次,JAVA的一次編寫(xiě),隨處運(yùn)行的特性意味著servlet可以在存在虛擬機(jī)(JVM)的操作系統(tǒng)間隨意移動(dòng)。</p><p>  Servlet類(lèi)似于一個(gè)微型web服務(wù)器。它接受請(qǐng)求并產(chǎn)生響應(yīng)。但是,與常規(guī)web服務(wù)器不同的是,servlet API 是專(zhuān)門(mén)用來(lái)幫助Java 開(kāi)發(fā)人員創(chuàng)建動(dòng)態(tài)應(yīng)用的。</p><p>  Servlet 自身是如同其他任何一個(gè)Java類(lèi),需要編譯成

91、字節(jié)碼文件的Java類(lèi)。Servlet訪問(wèn)HTTP 特定服務(wù)的API,但它仍然是一個(gè)運(yùn)行于程序之中的Java 對(duì)象并可以利用所有的Java 資產(chǎn)。</p><p>  為了使常規(guī)web服務(wù)器能訪問(wèn)servlet,servlet被安放在一個(gè)容器中。servlet容器連接web服務(wù)器。每個(gè)servlet 都可以聲明它想處理哪種URL。當(dāng)符合條件的請(qǐng)求到達(dá)web服務(wù)器的時(shí)候,web服務(wù)器將請(qǐng)求傳遞給servlet容器,

92、servlet容器則調(diào)用servlet。</p><p>  但是與CGI 程序不同,并不是每個(gè)請(qǐng)求都會(huì)創(chuàng)建新的servlet。一旦容器實(shí)例化了一個(gè)servlet,它就僅為每個(gè)新的請(qǐng)求創(chuàng)建一個(gè)新的線程。Java線程比CGI程序的服務(wù)器話費(fèi)要少很多。一旦servlet被創(chuàng)建,使用它處理額外的請(qǐng)求僅帶來(lái)很小的額外開(kāi)支。Servlet開(kāi)發(fā)人員可以使用init() 方法保持對(duì)昂貴資源的引用,比如連接數(shù)據(jù)庫(kù)或者EJB Ho

93、me接口等等,以便它們可以在不同的請(qǐng)求之間進(jìn)行共享資源。獲得這些資源需要好肥幾秒鐘的時(shí)間——這比大多數(shù)網(wǎng)上沖浪的人的最長(zhǎng)等待時(shí)間要長(zhǎng)一些。</p><p>  Servlet的另一個(gè)好處是,它可以多線程運(yùn)行,servlet開(kāi)發(fā)人員必須特別注意確保servlet是線程安全的。</p><p>  1.7 JavaServer Pages:</p><p>  對(duì)于CG

94、I程序servlets雖然前進(jìn)了一大步,但它也不是無(wú)敵的。為了產(chǎn)生響應(yīng),開(kāi)發(fā)人員仍然使用大量的println語(yǔ)句來(lái)生成HTML。代碼如下:</p><p>  out.println("<P>One line of HTML.</P>");</p><p>  out.println("<P>Another line of

95、HTML.</P>");</p><p>  在servlet中產(chǎn)生HTTP響應(yīng)是很正常的。也有一些庫(kù)來(lái)幫助你產(chǎn)生HTML,但是隨著應(yīng)用的日益復(fù)雜化,Java開(kāi)發(fā)人員脫離了HTML設(shè)計(jì)師的身份。與此同時(shí),給出這種選擇,大多數(shù)項(xiàng)目經(jīng)理更喜歡選擇將團(tuán)隊(duì)分成幾個(gè)小組來(lái)工作。 他們喜歡HTML設(shè)計(jì)人員處理表示層的工作,與此同時(shí)Java工程師則側(cè)重于業(yè)務(wù)邏輯。單獨(dú)使用servlet的場(chǎng)合下鼓勵(lì)混合標(biāo)記

96、和業(yè)務(wù)邏輯,這讓分組工作變得困難。</p><p>  為了解決這個(gè)問(wèn)題,Sun公司提出了一個(gè)將腳本和模板技術(shù)結(jié)合到一個(gè)組件中的服務(wù)器頁(yè)面技術(shù)(JavaServer Pages)。為構(gòu)建JSP頁(yè)面, 開(kāi)發(fā)人員開(kāi)始用以前創(chuàng)建HTML頁(yè)面的方式來(lái)創(chuàng)建頁(yè)面,使用HTML 語(yǔ)法。為了在頁(yè)面中引用動(dòng)態(tài)內(nèi)容,開(kāi)發(fā)人員還將腳本元素置入頁(yè)面之中。腳本元素是一些標(biāo)記語(yǔ)言壓縮了可以被JSP識(shí)別的邏輯。你可以在JSP頁(yè)面中簡(jiǎn)單的識(shí)別出

97、被壓縮在一對(duì)<% 和 %>標(biāo)記中的腳本元素。</p><p>  為了讓大家容易識(shí)別JSP頁(yè)面,JSP文件的擴(kuò)展名須為.jsp。</p><p>  當(dāng)一個(gè)客戶(hù)請(qǐng)求JSP頁(yè)面時(shí),容器將頁(yè)面翻譯成Java servlet 源代碼文件并將它編譯成Java 類(lèi)文件——就像你從零開(kāi)始寫(xiě)一個(gè)servlet文件一樣。運(yùn)行的時(shí)候,容器也可以檢測(cè)出JSP文件對(duì)應(yīng)的類(lèi)文件的最后更新時(shí)間。如果JS

98、P文件在上次編譯之后被修改過(guò),容器將再一次翻譯和編譯JSP文件。</p><p>  項(xiàng)目經(jīng)理現(xiàn)在可以將表示層工作分配給HTML 開(kāi)發(fā)人員,而 JAVA開(kāi)發(fā)人員將會(huì)被分配一些業(yè)務(wù)邏輯工作。一定要記住最重要的是JSP頁(yè)面其實(shí)就是一個(gè)servlet。用servlet可以處理的事,用JSP也可以處理。</p><p>  1.8 JavaBean:</p><p>  J

99、avaBean是一種符合一定的設(shè)計(jì)模式的 Java類(lèi)這樣的設(shè)計(jì)模式使它們易于和其他開(kāi)發(fā)工具和組件一起使用。</p><p>  定義:JavaBean 是一種用JAVA 語(yǔ)言寫(xiě)成的可重用組件。要編寫(xiě)一個(gè)JavaBean,類(lèi)必須是具體的公共類(lèi)(public),并且有無(wú)參構(gòu)造函數(shù)(NON-ARGS CONSTRUCTOR)。JavaBean把通過(guò)提供符合一致性的設(shè)計(jì)模式的public訪問(wèn)方法暴露的內(nèi)部字段稱(chēng)為屬性。眾

溫馨提示

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

評(píng)論

0/150

提交評(píng)論