The JSP (Java Server mix)technology is used by the Sun microsystem issued by the company to developdynamic Web application technology. With its easy, cross-platform, in manydynamic Web application programming languages, in a short span of a few years,has formed a complete set of standards, and widely used in electronic commerce,etc. In China, the JSP now also got more extensive attention, get a gooddevelopment, more and more dynamic website to JSP technology. The relatedtechnologies of JSP are briefly introduced.
The JSP a simple technology canquickly and with the method of generating Web pages. Use the JSP technology Webpage can be easily display dynamic content. The JSP technology are designed tomake the construction based on Web applications easier and efficient, and theseapplications and various Web server, application server, the browser anddevelopment tools work together.
The JSP technology isn't theonly dynamic web technology, also not the first one, in the JSP technologyexisted before the emergence of several excellent dynamic web technology, suchas CGI, ASP, etc. With the introduction of these technologies under dynamic webtechnology, the development and the JSP. Technical
JSP the development backgroundand development history
In web brief history, from aworld wide web that most of the network information static on stocktransactions evolution to acquisition of an operation and infrastructure. In avariety of applications, may be used for based on Web client, look norestrictions.
Based on the browser clientapplications than traditional based on client/server applications has severaladvantages. These benefits include almost no limit client access and extremelysimplified application deployment and management (to update an application,management personnel only need to change the program on a server, not thousandsof installation in client applications). So, the software industry is rapidlyto build on the client browser multi-layer application.
The rapid growth of exquisitebased Web application requirements development of technical improvements.Static HTML to show relatively static content is right choice, The newchallenge is to create the interaction based on Web applications, in these procedures,the content of a Web page is based on the user's request or the state of thesystem, and are not predefined characters.
For the problem of an earlysolution is to use a CGI - BIN interface. Developers write to interface withthe relevant procedures and separate based on Web applications, the latterthrough the Web server to invoke the former. This plan has serious problem --each new extensible CGI requirements in a new process on the server. Ifmultiple concurrent users access to this procedure, these processes will usethe Web server of all available resources, and the performance of the systemwill be reduced to extremely low.
Some Web server providers haveto provide for their server by plugins "and" the API to simplify theWeb application development. These solutions are associated with certain Webserver, cannot solve the span multiple suppliers solutions. For example,Microsoft's Active Server mix (ASP) technology in the Web page to createdynamic content more easily, but also can work in Microsoft on Personal WebServer and IIS.
There are other solutions, butcannot make an ordinary page designers can easily master. For example, such asthe Servlet Java technologies can use Java language interaction applicationserver code easier. Developers to write such Servlet to receive signals fromthe Web browser to generate an HTTP request, a dynamic response (may beinquires the database to finish the request), then send contain HTML or XMLdocuments to the response of the browser.
note: one is based on a Java Servlet Java technical operation in the server program (with different, thelatter operating in the Applet browser end). In this book the Servlet chapter4.
Using this method, the entirepage must have made in Java Servlet. If developers or Web managers want toadjust page, you'll have to edit and recompile the Servlet Java, even in logichas been able to run. Using this method, the dynamic content with theapplication of the page still need to develop skills.
Obviously, what is needed is aindustry to create dynamic content within the scope of the pages of thesolution. This program will solve the current scheme are limited. As follows:
can on any Webserver or applications.
will applicationpage displays and separation.
can rapidlydeveloping and testing.
simplify theinteractive development based on Web application process.
The JSP technology is designedto meet such requirements. The JSP specification is a Web server, applicationserver, trading system and develop extensive cooperation between the toolsuppliers. From this standard to develop the existing integration and balanceof Java programming environment (for example, Java Servlet and JavaBeans)support techniques and tools. The result is a kind of new and developing methodbased on Web applications, using component-based application logic pagedesigners with powerful functions.
Overall Semantics of a JSP Page
A JSP page implementation classdefines a _jspService() method mapping from the request to the response object.Some details of this transformation are specific to the scripting language used(see Chapter JSP.9, “Scripting”). Most details are not language specific and aredescribed in this chapter.
The content of a JSP page isdevoted largely to describing the data that is written into the output streamof the response. (The JSP container usually sends this data back to theclient.) The description is based on a JspWriter object that is exposed throughthe implicit object out (see Section JSP.1.8.3,“Implicit Objects”). Its value varies:
Initially, out is a newJspWriter object. This object may be different from the stream object returnedfrom response.getWriter(), and may be considered to be interposed on the latterin order to implement buffering (see Section JSP.1.10.1,“The page Directive”). This is the initial out object. JSP page authors areprohibited from writing directly to either the PrintWriter or OutputStream associatedwith the ServletResponse.
The JSP container should notinvoke response.getWriter() until the time when the first portion of thecontent is to be sent to the client. This enables a number of uses of JSP,including using JSP as a language to “glue” actions that deliver binarycontent, or reliably forwarding to a servlet, or change dynamically the contenttype of the response before generating content. See Chapter JSP.4,“Internationalization Issues”.
Within the body of some actions,out may be temporarily re-assigned to a different (nested) instance of aJspWriter object. Whether this is the case depends on the details of theaction’s semantics. Typically the content of these temporary streams isappended to the stream previously referred to by out, and out is subsequentlyre-assigned to refer to the previous (nesting) stream. Such nested streams arealways buffered, and require explicit flushing to a nesting stream or theircontents will be discarded.
If the initial out JspWriterobject is buffered, then depending upon the value of the autoFlush attribute ofthe page directive, the content of that buffer will either be automaticallyflushed out to the ServletResponse output stream to obviate overflow, or anexception shall be thrown to signal buffer overflow. If the initial outJspWriter is unbuffered, then content written to it will be passed directlythrough to the ServletResponse output stream.
A JSP page can also describewhat should happen when some specific events occur. In JSP 2.1, the only eventsthat can be described are the initialization and the destruction of the page.These events are described using “well-known method names” in declarationelements..
Servlets and JSPs often includefragments of information that are common to an organization, such as logos,copyrights, trademarks, or navigation bars. The web application uses theinclude mechanisms to import the information wherever it is needed, since it iseasier to change content in one place then to maintain it in every piece ofcode where it is used. Some of this information is static and either never orrarely changes, such as an organization's logo. In other cases, the informationis more dynamic and changes often and unpredictably, such as a textual greetingthat must be localized for each user. In both cases, you want to ensure thatthe servlet or JSP can evolve independently of its included content, and thatthe implementation of the servlet or JSP properly updates its included contentas necessary.
You want to include a resourcethat does not change very much (such as a page fragment that represents aheader or footer) in a JSP. Use the include directive in the including JSPpage, and give the included JSP segment a .jspf extension.
You want to include content in aJSP each time it receives a request, rather than when the JSP is converted to aservlet. Use the jsp:include standard action.
You want to include a filedynamically in a JSP, based on a value derived from a configuration file. Usethe jsp:include standard action. Provide the value in an external propertiesfile or as a configuration parameter in the deployment descriptor.
You want to include a fragmentof an XML file inside of a JSP document, or include a JSP page in XML syntax.Use the jsp:include standard action for the includes that you want to occurwith each request of the JSP. Use the jsp:directive.include element if theinclude action should occur during the translation phase.
You want to include a JSP segment from outside the including file'scontext. Use the c:import
The operation principle and the advantages of JSP tags
In this section of the operating principle of simple introductionJSP and strengths.
For the first time in a JSP documents requested by the engine, JSPServlet is transformed into a document JSP. This engine is itself a Servlet.The operating process of the JSP shown below:
(1) the JSP engine put the JSP files converting a Java source files(Servlet), if you find the files have any grammar mistake JSP, conversionprocess will interrupt, and to the server and client output error messages.
(2) if converted, with the engine JSP javac Java source filecompiler into a corresponding scale-up files.
(3) to create a the Servlet (JSP page), the transformation of theServlet jspInit () method was executed, jspInit () method in the life cycle ofServlet executed only once.
(4) jspService () method invocation to the client requests. For eachrequest, JSP engine to create a new thread for processing the request. If youhave multiple clients and request the JSP files, JSP engine will createmultiple threads. Each client requests a thread. To execute multi-thread cangreatly reduce the requirement of system resources, improving the concurrencyvalue and response time. But also should notice the multi-thread programming, dueto the limited Servlet always in response to memory, so is very fast.
(5) if the file has been modified. The JSP, server will be setaccording to the document to decide whether to recompile, if need to recompile,will replace the Servlet compile the memory and continue the process.
(6) although the JSP efficiency is high, but at first when the needto convert and compile and some slight delay. In addition, if at any time dueto reasons of system resources, JSP engine will in some way of uncertainServlet will remove from memory. When this happens jspDestroy () method wasfirst call.
(7) and then Servlet examples were marked with "add"garbage collection. But in jspInit () some initialization work, if establishconnection with database, or to establish a network connection, from aconfiguration file take some parameters, such as, in jspDestory () release ofthe corresponding resources.
Based on a Java language has many other techniques JSP page dynamiccharacteristics, technical have embodied in the following aspects:
One simplicity and effectiveness
The JSP dynamic web pages with the compilation of the static HTMLpages of writing is very similar. Just in the original HTML page add JSP tags,or some of the proprietary scripting (this is not necessary). So, a familiarwith HTML page write design personnel may be easily performed JSP pagedevelopment. And the developers can not only, and write script by JSP tags usedexclusively others have written parts to realize dynamic pages. So, anunfamiliar with the web developers scripting language, can use the JSP makebeautiful dynamic pages. And this in other dynamic web development isimpossible.
Tow the independence of the program
The JSP are part of the family of the API Java, it has the generalcharacteristics of the cross-platform Java program. In other words, is to havethe procedure, namely the independence of the platform, 6 Write bided anywhere!.
Three procedures compatibility
The dynamic content can various JSP form, so it can show for allkinds of customers, namely from using HTML/DHTML browser to use varioushandheld wireless equipment WML (for example, mobile phones and pdas), personaldigital equipment to use XML applications, all can use B2B JSP dynamic pages.
Four program reusability
In the JSP page can not directly, but embedded scripting dynamicinteraction will be cited as a component part. So, once such a component towrite, it can be repeated several procedures, the program of the reusability.Now, a lot of standard JavaBeans library is a good example.