JSP white paper

zhaozj2021-02-08  208

JavaServer PageSTM (JSP) technology provides a simple and fast way to create a web page that displays dynamically generated content. The design purpose of JSP technology is to make it easier and short to construct web-based applications, and these applications work with a variety of web servers, application servers, browsers, and development tools.

This white paper provides a comprehensive overview of JSP technology, which describes its development background and overall goals of this technology. At the same time, in a simple example, a key component of a page based on JavaTM technology is also described.

Develop web-based applications: background

In a short history of the World Wide Web, it has evolved from a network that shows static information to an infrastructure for trading and booking operations for stocks. In a wide variety of applications, there is no restriction on the web-based client that may be used.

Browser-based applications have several benefits than traditional client / server-based applications. These benefits include almost unlimited client access and extremely simplified applications deployment and management (to update an application, the administrator only needs to change a server-based program, rather than thousands of applications installed on the client. ). In this way, the software industry is quickly moving towards the construction of a browser-based multi-level application.

These rapidly grown Web-based applications require development technologies. Static HTML is a good choice for displaying relative static content; new challenges are web-based applications that create interactions. In these programs, the contents of the page are based on the user's request or system, not a pre-defined text. .

An early solution for this issue is to use the CGI-BIN interface; developers write separate programs related to interfaces, as well as web-based applications, the latter call the former through the web server. This scenario has a serious extensibility problem - each new CGI requires a new process on the server. If multiple users have access to the program, these processes will consume all available resources for the web server, and system performance is reduced to extremely low.

Some web server vendors have tried to simplify the development of web applications by providing "plugins" and APIs for their servers. These solutions are related to specific web servers and cannot address solutions across multiple suppliers. For example, Microsoft's Active Server PageSTM (ASP) technology makes it easier to create dynamic content on the web page, but can only work on Microsoft's IIS and Personal Web Server.

There are other solutions, but you can't make a normal page designer can easily master. For example, a technique like Java Servlets can make the code of the server-side server-side server-side of the application with Java language easier. A Java servlets is a program based on the server-based server (unlike Applet, the latter runs in the browser). Developers can write such a servlet to receive HTTP requests from a web browser, dynamically generate responses (may query the database to complete this request), and then send a response to the browser that contains HTML or XML documents.

With this method, the entire web page must be made in the Java Servlet. If the developer or web manager wants to adjust the page display, you have to edit and recompile the Java Servlet, even if it is logically already running. With this method, generating a page with dynamic content still requires the development skills of the application.

Obviously, what is currently needed is a solution to create a dynamic content page within an industry. This program will solve the restrictions received by the current solution, namely:

Can run on any web or application server

Separate application logic and page display

Ability to develop and test quickly

Simplify the process of developing web-based interactive applications

JavaServer Pages (JSP) technology is designed to meet this requirement. The JSP specification is the result of the broad cooperation between web servers, application servers, trading systems, and development tools. Sun Microsystems Inc. Developed this specification to integrate and balance technology and tools that have existed for Java programming environments (for example, Java Servlet and JavaBeansTM). The result is a new, developing a web application-based approach, giving a powerful feature based on page designers based on component application logic. JavaServer Pages technology for web applications

During the development of JSP specifications, Sun Microsystems Inc., with many major web servers, application servers, and development tools, and cooperation in various experienced development groups. The result is a development method for balancing portability and ease of use for applications and page developers.

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

Separate the generation and display of the content

With JSP technology, web page developers can use HTML or XML identity to design and format the final page. Use the JSP identifier or the small script to generate dynamic content on the page (content is based on request, such as requesting account information or a specific bottle of wine). The logic of generating content is packaged in the identification and javabeans components, and bundled in a small script, all scripts run on the server. If the core logic is encapsulated in the identification and beans, then others, such as web managers and page designers, can edit and use the JSP page without affecting the generation of content.

In the server side, the JSP engine explains the JSP ID and the small script, generates the requested content (for example, by accessing the JavaBeans component, using the JDBCTM technology to access the database, or contains the file), and send the result in the form of an HTML (or XML) page Back to the browser. This helps the author to protect your code, and guarantee any HTML-based web browser full availability.

Emphasize reusable components

Most JSP pages depends on the more complex processing required by the application, cross-platform components (JavaBeans or Enterprise JavaBeansTM components). Developers can share and exchange components that perform ordinary operations, or make these components used for more users or customer groups. Component-based methods accelerate the overall development process, and make various organizations balance in their existing skills and optimization results development efforts.

Simplify page development with identification

Web page developers will not be familiar with programmers for scripting languages. JavaServer Page technology has enabled many features that are desired to be dynamically generated in ease of use, dynamic content generation in the XML identity associated with JSP. Standard JSP Identifies to access and instantiate the JavaBeans component, setting, or retrieving component properties, downloading applets, and making other methods more difficult to encode and time consuming.

JSP technology can be extended by developing customized logo depots. In the future, third-party developers and other personnel can create their own logo available for common functions. This allows web page developers to operate using familiar tools and components that perform specific functions like identifiers.

JSP technology is easy to integrate into a variety of application architecture to utilize existing tools and techniques, and extend to support enterprise-class distributed applications. As part of the Java technical family, as well as Java 2 (Enterprise Edition Architecture), JSP technology supports highly complex web-based applications.

Since the built-in scripting language of the JSP page is based on Java programming languages, and all JSP pages are compiled into Java Servlet, the JSP page has all benefits of Java technology, including robust storage management and security. As part of the Java platform, JSP has the characteristics of Java programming languages ​​"a written, running". As more and more suppliers add JSP support to their products, you can use your own server and tools, change tools, or servers do not affect the current application.

When integrating with the Java 2 platform, Enterprise Edition (J2EE) and Enterprise JavaBean, JSP pages will provide enterprise-class scalability and performance, which is required for deploying web-based applications in virtual enterprises.

What is the JSP page look like?

The JSP page looks like standard HTML and XML pages and attached to additional components with JSP engines to handle and extract. Typically, the JSP component creates text inserted into the final page.

Using an example is the best way to describe JSP technology. The following JSP page is very simple; it prints the year, the day the day, and it is welcome to use "Good Morning" and "Good Afternoon" based on time.

This page combines ordinary HTML and a large number of JSP components.

Call for clock JavaBeans components

Contains for an external file (for copyright information)

JSP expressions and scripts

<% @ page language == "java" imports == "com.wombat.jsp. *"%>

Welcome

Today is

  • day: <% == clock.getdayofmonth ()%>

  • year: <% == clock.getYear ()%>

    <% IF (Calendar.GetInstance (). get (Calendar.Am_PM) ==== Calendar.am) {%>

    Good morning

    <%} else {%>

    Good afternoon

    <%}%>

    <% @ include file == "CopyRight.html"%>

    This page contains the following components:

    A JSP instruction is transmitted to the JSP engine. In this example, the first line indicates the location of some Java programming languages ​​from which the page is about to be accessed. The indication is set in <% @ and%> tags.

    Fixed template data: The identity that all JSP engines cannot be identified will be sent with the result page. Typically, these identities are HTML or XML identifiers. In the example above, the unmanage list (UL) and H1 identification are included.

    JSP Action or Identification: These are usually implemented as standard or custom identifiers, and have an XML identifier. In this example, the JSP: USEBean identifies the Clock JavaBean of the instantiated server.

    An expression: JSP engine calculates everything between <% == and%> tags. In the list items above, the DAY and YEAR attribute values ​​of the clock component (Clock) are returned as a string and inserted into the JSP file as an output. In the above example, the first list item is the day, the second is the year. The small script is a small script that performs the functions supported by the identity or bundles all things together. The built-in scripting language of JSP 1.0 software is based on Java language. The small script in the example above determines that it is still afternoon, and accordingly, users are welcome.

    This example may be a little bit, but the technology is not. The key processing can be encapsulated from the server side, and the web developers can easily access this information using familiar grammar and tools. Java-based small scripts provide a flexible way to perform other features without requiring extended scripting languages. The page is readily readable as a whole, which makes it look for or prevents problems and

    Sharing work is easier.

    Parts in these components have a more detailed description below.

    JSP instructions

    The JSP page uses JSP instructions to pass the instruction to the JSP engine. This includes:

    The JSP page indicates the transfer page related information, such as buffers and thread information or error processing.

    Language indicates that the scripting language is specified, and all extensions.

    A indication (display in the above example) can be used to include an external document in the page. A good example is a copyright document or a company information document - saves the document in a central location and contains more than the update than in each JSP page. Of course, the file being included may also be another JSP file.

    The logo library indicates a customer logo library that can be called by the page.

    JSP logo

    Most JSP processing will be completed by XML-based identity associated with JSP. The JSP 1.0 contains a large number of standard identities, which as the core identity includes:

    JSP: UseBean This identity declares for use of a JavaBeans component instance. If the instance of the component does not exist, the JavaBeans component will instantiate and register this identity.

    JSP: SetProperty This identifier sets the value of an attribute in an instance of the component.

    JSP: getProperty This identifies the properties value of the instance of a component, converts it into a string, and put it in an implicit object "OUT".

    JSP: incrude

    JSP: Forward

    The 1.1 version will contain more standard identities.

    The advantage of identification is that they are easy to use and share between applications. The true power of the logo-based syntax comes from the development of the customer identity library, making tool providers or other personnel to create and assume the identity for specific requirements.

    Script component

    The JSP page can contain small scripts in the page, called Scriptlets. The small script is a code snippet that is executed during the process of the request. The small script can create a dynamically generated page with the static component combination in the page (as in the example above).

    The script is described in <% and%> flags. Everything in this pair of flags will be executed by the script description language engine, and in our example is the Java virtual machine on the host.

    The JSP specification supports all common script components, 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 on the application server using the JSP. The JSP engine accepts the request for the client to the JSP page and generates a response to the client.

    The JSP page is usually compiled into a Java servlet. The latter is a standard Java extension, which has a more detailed description at www.java.sun.com. Page developers can access all Java application environments to utilize Java technology scalability and portability.

    When the JSP page is called for the first time, if it still does not exist, it will be compiled into a Java Servlet class and stored in the server's memory. This makes a very fast response in the next call. (This avoids CGI-bin to generate a new process for each HTTP request, or the runtime syntax analysis caused by server-side references.) The JSP page can be included in a variety of different application architectures or models. The JSP page can be used in a consortium composed of different protocols, components, and formats. The following section describes some possible situations.

    A simple application

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

    This model is basically replaced with the CGI-BIN concept with a JSP page (compiled into a Java servlet). This method has the following advantages:

    Simple and fast programming

    Page authors can easily generate dynamic content according to requests and resource status

    This structure works well in many applications, but cannot extend to a large number of web-based concurrent customers access rare enterprise resources, because each customer must establish or share a connection to the available content resources. For example, if the JSP page accesss the database, there may be many connections to the database, which will affect the performance of the database.

    A flexible application using Java Servlet

    In another possible configuration, web-based clients may directly request the Java Servlet, and servlet generate dynamic content, bundle the results into a result object and call the JSP page. The JSP page accesses dynamic content from this object and sends the result (eg, HTML) back to the browser.

    This method creates more reusable components that can be shared between applications, and can be done as part of a larger application. However, there is still a scalability issue when handling the connection as a database of a database.

    Extensible processing of enterprise JavaBean technology

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

    The EJB component manages access to backend resources, providing scalable performance for many concurrent users. For e-commerce or other applications, EJB management transactions and potential security. This will simplify the JSP page. This model will be supported by the Java 2 Enterprise (J2EE) platform.

    JSP page and integration of XML technology

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

    For simple XML generation, developers can include a static template section of the XML identity and JSP page. For dynamic XML generation, use a server-based object and a customized identity that generates XML output.

    The JSP page is not incompatible with the XML tool. Although Sun is designed to design the JSP specification, the JSP page is also very easy to manually operate, and JSP specification also provides a mechanism to facilitate an XML version of any JSP page. In this way, the XML tool creates and operates the JSP page.

    The JSP page can be operated using XML-based tools by converting JSP identity and components to an XML-compatible peer. For example, scripts can be included in <% and%>, or in the and based on XML flags. In fact, it is possible to convert JSP pages to an XML page after a few steps below. These steps include:

    Add a JSP root element

    Convert components and instructions to XML compatible peers

    Create a CDATA component for other components (usually non-JSP) on the page

    Through this method compatible with XML, the designer created the HTML page still has a easy-to-use environment that quickly creates a dynamic web page, while XML-based tools and services can be integrated with JSP pages and work together with JSP-compatible servers. JSP technology's future

    JSP technology is designed as an open and scalable build dynamic web page standard. Developers can use JSP pages to create portable web applications, running on different web and application servers, regardless of what is suitable for their own occasions and needs.

    By cooperating with industry leaders, Sun assurance JSP specification is open and portable. You can use any clients and server platforms to write and deploy them anywhere. In the future, tool vendors and other vendors will extend the functionality of the platform by providing a customized logo library for specialized features.

    The 1.0 version of the JSP specification is the first step in an open industrial standard approach to the dynamic web page. 1.0 Version The basic functionality required to create a dynamic web page is constituted by a core identification set, implied object, and the basic functionality required to create a dynamic web page. There are several web servers, application servers, and development tools that have added JSP1.0 support for their products, so that in the industry already has the initial, immediate support.

    The version 1.1 will be completed later in 1999, expand this version through more XML support, customized identity, and integration with J2EE. And suppliers may have selection and expand the basic and necessary functionality in the JSP specification. The JSP engine can strongly support multiple scripting languages ​​and object models. While expanding and using JSP technology capabilities while using JSP technology, the SUN is committed to maintaining the inherent portability of the platform and server.

转载请注明原文地址:https://www.9cbs.com/read-2548.html

New Post(0)