JSP technical whitepaper

Source: Internet
Author: User
Java Server pagestm (JSP) technology provides a simple and fast way to create a web page that displays dynamically generated content. JSP technology is designed to make it easier and faster to Construct Web-based applications that work with various web servers, application servers, browsers, and development tools.

This White Paper provides a comprehensive overview of JSP technology, describes its development background and the overall goal of this technology. In addition, a simple example describes the key components of a page based on the javatm technology.

Develop Web-based applications: Background

In the short history of the world wide web, it has evolved from a network that shows a majority of static information to an infrastructure for stock trading and book purchasing. In a variety of applications, there seems to be no restrictions on web-based clients that may be used.

Browser-based client applications have several advantages over traditional Client/Server-based applications. These benefits include almost unlimited client access and extremely simplified application deployment and management (to update an application, the Administrator only needs to change a server-based program, instead of thousands of applications installed on the client ). In this way, the software industry is rapidly moving towards the construction of multi-layer applications based on browser clients.

These fast-growing sophisticated Web-based applications require technical improvements in development. Static HTML is a good choice for displaying relatively static content. The new challenge is to create interactive web-based applications. Among these applications, the page content is based on the user's request or system status, rather than pre-defined text.

An early solution to this problem was the use of CGI-BIN interfaces; developers wrote separate programs related to interfaces, as well as web-based applications, which call the former through web servers. This solution has serious scalability problems-each new CGI requires a new process to be added to the server. If multiple users access the program concurrently, these processes will consume all the available resources of the Web server, and the system performance will be reduced to an extremely low level.

Some Web server vendors have tried to simplify Web application development by providing plug-ins and APIs for their servers. These solutions are related to specific Web servers and cannot solve cross-vendor solutions. For example, Microsoft's Active Server PagesTM (ASP) technology makes it easier to create dynamic content on Web pages, but it can only work on Microsoft's IIS and Personal Web Server.

There are other solutions, but they cannot be easily mastered by a common page designer. For example, a technology like Java Servlets makes it easy to write the server-side code of an interactive application in Java. A Java Servlets is a Java-based program running on the server (unlike the Applet, which runs on the browser ). Developers can compile such Servlets to receive HTTP requests from Web browsers and dynamically generate responses (the database may be queried to complete this request ), then, send a response containing HTML or XML documents to the browser.

In this way, the entire webpage must be created in Java Servlet. If developers or Web administrators want to adjust the page display, they have to edit and re-compile the Java Servlet, even if it can be run logically. Using this method, the development skills of applications are still required to generate pages with dynamic content.

Obviously, what we need now is an industry-wide solution for creating dynamic content pages. This solution solves the restrictions imposed by the current solution, namely:

Able to run on any Web or Application Server
Separating application logic from page display
Fast development and testing
Simplify the process of developing Web-based interactive applications
The assumerver Pages (JSP) technology is designed to meet such requirements. JSP specification is the result of extensive cooperation among Web servers, application servers, transaction systems, and development tool vendors. Sun Microsystems Inc. has developed this specification to integrate and balance existing technologies and tools that support Java programming environments (such as Java Servlet and JavaBeansTM. The result is a new method for developing Web applications, which provides powerful functions for page designers who use component application logic.

Web Application Development's assumerver Pages Technical Method

Sun Microsystems Inc .) cooperation with many major Web servers, application servers and development tool vendors, as well as various experienced development groups. The result is a development method that balances portability and ease of use between applications and page developers.

JSP Technology accelerates the development of dynamic web pages in multiple aspects:

Separate content generation and display

With JSP technology, Web page developers can use HTML or XML tags to design and format the final page. Use JSP identifiers or small scripts to generate dynamic content on the page (the content varies according to the request, such as requesting account information or the price of a specific bottle of wine ). The logic of the generated content is encapsulated in the identifiers and JavaBeans components and bundled in small scripts. All scripts run on the server. If the core logic is encapsulated in identifiers and Beans, other people, such as Web administrators and page designers, can edit and use JSP pages without affecting content generation.
On the server side, the JSP Engine interprets JSP identifiers and small scripts to generate the requested content (for example, accessing the JavaBeans component, using the JDBCTM technology to access the database, or including files ), in addition, the results are sent back to the browser in the form of HTML (or XML) pages. This helps the author protect his own code and ensure the full availability of any HTML-based Web browser.

Reusable components

Most JSP pages depend on reusable cross-platform components (JavaBeans or enterprise javabeanstm components) to perform more complex processing required by applications. Developers can share and exchange components that perform common operations, or make these components used by more users or customer groups. The Component-Based Approach accelerates the overall development process and balances various organizations in their development efforts with their existing skills and optimization results.

Simplified page development with logo

Web page developers are not all programmers familiar with the scripting language. The assumerver page technology encapsulates many functions that are required for dynamic content generation in easy-to-use and JSP-related XML identifiers. The standard JSP mark can access and instantiate the JavaBeans component, set or retrieve component attributes, download the applet, and execute functions that are more difficult to encode and consume in other ways.
Through the development of a custom identification library, JSP technology can be expanded. In the future, third-party developers and others can create their own identification libraries for common functions. This allows web page developers to work with familiar tools and components that execute specific functions like identifiers.

JSP technology can easily be integrated into a variety of application architectures to take advantage of existing tools and techniques and extend to support enterprise-level distributed applications. As part of the Java technology family and an integral part of Java 2 (Enterprise Edition architecture), JSP technology can support highly complex web-based applications.
Because the built-in scripting language of JSP pages is based on the Java programming language, and all JSP pages are compiled into Java Servlets, JSP pages have all the advantages of Java technology, including robust storage management and security.
As part of the Java platform, JSP features the Java programming language "one-time writing, running everywhere. As more and more vendors add JSP support to their products, you can use the servers and tools you select. Changing tools or servers does not affect the current application.
When integrated with Java 2 platform, Enterprise Edition (J2EE), and Enterprise JavaBean technology, JSP pages provide enterprise-level scalability and performance, this is required for deploying web-based applications in Virtual Enterprises.

What does a JSP page look like?
JSP pages look like standard HTML and XML pages, with additional elements that the JSP engine can process and extract. Generally, JSP elements are used to create the text inserted into the final page.

The example is the best way to describe JSP technology. The following JSP page is very simple. It prints the day of the year and month, and welcomes you by using "good morning" and "good afternoon.

This page is composed of common HTML and a large number of JSP elements.

Call the clock JavaBeans component
Include an external file (for copyright information)
JSP expressions and scripts
<HTML>
<% @ Page Language = "Java" Imports = "com. Wombat. jsp. *" %>
<H1> welcome

<P> today is </P>
<JSP: usebean id = "Clock" class = "calendar. jspcalendar"/>
<Ul>
<Li> day: <% = clock. getdayofmonth () %>
<Li> year: <% = clock. getyear () %>
</Ul>

<% IF (calendar. getinstance (). Get (calendar. am_pm) === calendar. am) {%>
Good morning
<%} Else {%>
Good afternoon
<% }%>
<% @ Include file = "copyright.html" %>

</HTML>

This page contains the following components:

A JSP indicates that information is transmitted to the JSP Engine. In this example, the first line shows the extensions of some Java programming languages to be accessed from this page. Indicates to be set in the <% @ and %> flag.
Fixed template data: All identifiers that cannot be identified by the JSP engine are sent along with the results page. Generally, these identifiers are HTML or XML identifiers. In the preceding example, the unordered list (UL) and H1 identifiers are included.
JSP actions or identifiers: these are generally implemented as standard or custom identifiers and have the syntax for XML identifiers. In this example, jsp: useBean identifies the Clock JavaBean of the instantiated server.
One expression: the JSP Engine computes everything between the <% == and %> mark. In the preceding list, the value of Day and Year of the Clock component (Clock) is returned as a string and inserted into the JSP file as an output. In the preceding example, the first item in the list is the day and the second item is the year.
Script is a small script that executes functions not supported by the identity or binds everything together. The built-in scripting language of JSP 1.0 is based on the Java language. The script in the above example confirms whether it is morning or afternoon, and welcomes the user accordingly.
This example may be a little small, but technically not. In terms of business, key processing can be encapsulated in server components, and Web developers can easily access this information using familiar syntaxes and tools. Java-based small scripts provide a flexible way to execute other functions without requiring additional scripting languages. The page as a whole is readable and understandable, which enables you to find or prevent problems and
Sharing is easier.
Some of these components are described in more detail below.

JSP indication

The JSP page uses JSP instructions to pass commands to the JSP Engine. These include:

JSP page indicates passing page-related information, such as buffer and thread information or error handling.
Language indication specifies the scripting language and all extensions.
Contains instructions (shown in the preceding example) can be used to include an external document in the page. A good example is the copyright document or company information document-it is easier to save the document in a centralized location and include it on the page than to update it on each JSP page. Of course, the contained file may also be another JSP file.
The ID library indicates a customer ID library that can be called on the page.

JSP ID

The vast majority of JSP processing will be done through JSP-related XML-based identifiers. JSP 1.0 contains a large number of standard identifiers as core identifiers, including:

JSP: usebean indicates the use of a JavaBeans component instance. If the instance of this component does not exist, the JavaBeans component will instantiate and register this identifier.
JSP: setproperty: This identifier sets an attribute value in the component instance.

JSP: getproperty: This identifier gets the property value of an instance of a component, converts it to a string, and puts it in the hidden object "out.

JSP: Include

JSP: Forward

Version 1.1 contains more standard identifiers.

The advantage of identifiers is that they are easy to use and share between applications. The real power of the logo-based syntax comes from the development of the customer identification library, so that the tool supplier or other personnel can create and assign tags for specific requirements.

Script Element

A JSP page can contain small scripts, which are called scriptlets ). The script is a code snippet that is executed during request processing. A small script can be combined with static components in the page (as in the preceding example) to create a dynamically generated page.

The script is described in the <% and %> flag. Everything in this pair of labels will be executed by the script Description Language engine. In our example, it is the Java Virtual Machine on the host.

JSP specifications support all common script elements, including expressions and declarations.

JSP page application model

The JSP page is executed by the JSP engine. The engine is installed on the Web server or the JSP application server. The JSP Engine accepts requests from the client to the JSP page and generates a response from the JSP page to the client.

JSP pages are usually compiled into Java Servlets. The latter is a standard Java extension, which has a more detailed description on the site www.java.sun.com. Page developers can access all Java application environments to utilize the scalability and portability of Java technology.

When a JSP page is called for the first time, if it does not exist, it will be compiled into a Java Servlet class and stored in the server's memory. This gives a very fast response to the next call to this page. (This avoids the problem of a CGI-BIN generating a new process for each HTTP request, or the runtime syntax analysis caused by server-side references .)

JSP pages can be contained in a variety of application architectures or models. JSP pages can be used in a consortium composed of different protocols, components, and formats. The following sections describe some possible situations.

A simple application

In a simple implementation, the browser calls the JSP page directly, and the JSP page generates the requested content (JDBC may be called to directly obtain information from the database ). JSP pages can call JDBC or Java BlendTM components to generate results, and create standard HTML and send the results back to the browser.

This model basically replaces the CGI-BIN concept with JSP pages (compiled into a Java Servlet. This method has the following advantages:

Simple and fast Programming
Page authors can easily generate dynamic content based on the request and Resource Status
This structure works well in many applications, but it cannot be extended to a large number of Web-Based Concurrent customers to access scarce enterprise resources, because each customer must establish or share a connection to available content resources. For example, if the JSP page accesses the database, many connections to the database may be generated, which affects the database performance.

A flexible application using Java Servlet

In another possible configuration, a Web-based client may directly request the Java Servlet. The Servlet generates dynamic content, binds the results to a result object, and calls the JSP page. JSP pages Access dynamic content from this object and send the results (such as HTML) back to the browser.

This method creates more reusable components that can be shared among applications and can be completed as part of a larger application. However, there is still a scalability problem when handling connections to enterprise resources like databases.

Scalable processing using enterprise-level JavaBean technology

The JSP page can also be used as an intermediate layer in the enterprise-level JavaBean (EJB) architecture. In this case, the JSP page interacts with the backend resources through the EJB component.

The EJB component manages access to backend resources to provide Scalable Performance for a large number of concurrent users. For e-commerce or other applications, EJB manages transactions and potential security. This simplifies the JSP page. This model will be supported by the Java 2 Enterprise Edition (J2EE) platform.

Integration of JSP pages and XML Technology

JSP pages can be used to generate XML and HTML pages.

For simple XML generation, developers can include XML identifiers and static templates of JSP pages. For dynamic XML generation, use server-based objects and custom identifiers that generate XML output.

JSP pages are not incompatible with XML tools. Although Sun makes it easy for creators to manually operate JSP pages when designing JSP specifications, JSP specifications also provide a mechanism to create an XML version of any JSP page. In this way, the XML tool can create and operate JSP pages.

By converting JSP identifiers and components into XML-compatible peers, you can use XML-based tools to operate JSP pages. For example, a script can be included in <% and %>, or <jsp: scriptlet> and </jsp: scriptlet> Based on the XML flag. In fact, it is possible to convert a JSP page to an XML page through the following simple steps:

Add a JSP root component

Convert components and indications to XML-compatible peers
Create CDATA components for other components (usually non-JSP) on the page
Using this XML-compatible method, the designers who create HTML pages still have an easy-to-use environment to quickly create dynamic web pages. At the same time, XML-based tools and services can be integrated with JSP pages and work with JSP-compatible servers.

The future of JSP Technology

JSP technology is designed as an open and scalable standard for building dynamic web pages. Developers can use JSP pages to create portable Web applications and run them on different Web and application servers for different occasions, no matter what creation tools are suitable for your own scenarios and needs.

Through cooperation with industry leaders, Sun ensures that JSP specifications are open and portable. You can use any client or server platform to write and deploy them anywhere. In the future, tool suppliers and other vendors will expand the platform's functions by providing custom identification libraries for specialized functions.

JSP Specification Version 1.0 is the first step towards an open industrial standard method for dynamic Web page generation. Version 1.0 forms the basis of this method through a core set of identifiers, hidden objects, and the basic functions required to start creating dynamic Web pages. There are already several Web servers. application servers and development tool vendors are adding JSP1.0 support for their products, so they already have the initial and immediate support in the industry.

Later in version 1999, the version will be extended through more XML support, custom identifiers, and integration with J2EE. Suppliers may also selectively expand and expand the basic and necessary functions in JSP specifications. The JSP Engine supports multiple scripting languages and object models. While expanding and Using JSP technology capabilities in the industry, Sun also promised to ensure that JSP technology maintains inherent portability between the platform and the server.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.