Javaserverpages White Paper

Source: Internet
Author: User
Tags add object end error handling extend final functions version
Erp|server JavaServer pagestm (JSP) technology provides a simple and quick way to create Web pages that display dynamically generated content. JSP technology is designed to make it easier and faster to build web-based applications that work with a variety of Web servers, application servers, browsers, and development tools.
This white paper provides a comprehensive overview of JSP technology, describing its development background and the overall objectives of the technology. Also, in a simple example, a key component of a page based on JAVATM technology is described.

Developing web-based applications: Background

In the short history of the World Wide Web, it has evolved from a network that largely displays static information to an infrastructure for trading and book-buying operations on stocks. In a variety of applications, there seems to be no limit to the web-based client that might be used.

Browser-based client based 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, managers need to change only one server-based program, not tens of thousands of applications installed on the client). In this way, the software industry is rapidly moving towards the construction of Multi-tiered applications based on browser clients.

These fast-growing and sophisticated web-based applications require the development of technical improvements. Static HTML is a good choice for displaying relatively static content; The new challenge is to create interactive web-based applications in which the content of the page is based on the user's request or the state of the system, rather than the predefined text.

An early solution to this problem is to use the Cgi-bin interface, where developers write separate programs related to interfaces, and web-based applications that invoke the former through a Web server. This program has a serious extensibility problem?? Each new CGI requires the addition of a process on the server. If multiple users access the program concurrently, these processes will consume all of the available resources on the Web server and degrade the system to a very low level.

Some Web server vendors have tried to simplify the development of Web applications by providing "Plug-ins" and APIs for their servers. These solutions are related to a particular Web server and do not solve the problem of solutions across multiple vendors. For example, Microsoft's active Server pagestm (ASP) technology makes it easier to create dynamic content on Web pages, but it works only on Microsoft's IIS and personal Web servers.

There are other solutions, but none of them can be easily mastered by an ordinary page designer. For example, a technology like the Java Servlets makes it easy to make server-side code for applications that interact in the Java language. A Java servlets is a Java-technology-based program that runs on the server side (unlike applets, which run on the browser side). Developers can write such a servlet to receive HTTP requests from Web browsers, dynamically generate responses (possibly querying the database to complete the request), and then send a response to the browser that contains HTML or XML documents.

With this approach, the entire Web page must be made in the Java servlet. If a developer or Web administrator wants to adjust the page display, they will have to edit and recompile the Java Servlet, even if they are logically operational. In this way, generating pages with dynamic content still requires application development techniques.

Clearly, what is needed now is an industry-wide solution for creating dynamic content pages. This solution will address the limitations of the current scenario, namely:

Ability to run on any Web or application server
Separating application logic from page display
Ability to quickly develop and test
Simplifying the process of developing web-based interactive applications
JavaServer Pages (JSP) technology is designed to meet such requirements. The JSP specification is the result of extensive collaboration between Web servers, application servers, trading systems, and development tool vendors. Solar Microsystems Inc. (Sun Microsystems Inc.) Develop this specification to consolidate and balance existing technologies and tools that support the Java programming environment (for example, Java servlet and javabeanstm). The result is a new approach to developing web-based applications that gives powerful functionality to page designers who use component-based application logic.
JavaServer Pages Technology for Web application development

In the process of developing JSP specifications, Sun Microsystems Inc. Collaborate with a large number of major Web servers, application servers, and development tool vendors, as well as a wide variety of experienced development groups. The result is a development approach that balances portability and ease of use for application and page developers.

JSP technology accelerates the development of dynamic Web pages in several ways:

Separating the generation and display of content
Using JSP technology, Web page developers can use HTML or XML identities to design and format final pages. Use a JSP logo or a little script to generate dynamic content on the page (content varies according to request, such as requesting account information or the price of a particular bottle of wine). The logic for generating content is encapsulated in identity and JavaBeans components, and bundled in small scripts, all scripts run on the server side. If the core logic is encapsulated in logos and beans, then others, such as Web managers and page designers, can edit and use JSP pages without affecting the generation of content.
On the server side, the JSP engine interprets JSP IDs and small scripts to generate the requested content (for example, by accessing the JavaBeans component, accessing the database using JDBCTM technology, or including files), and sending the results back to the browser as an HTML (or XML) page. This helps authors protect their own code while ensuring the full availability of any html-based Web browser.

Emphasis on reusable components
Most JSP pages rely on reusable, cross-platform components (JavaBeans or Enterprise javabeanstm components) to perform the more complex processing required by the application. Developers can share and Exchange components that perform common operations or make these components available to more users or customer groups. The component-based approach accelerates the overall development process and enables organizations to balance their existing skills and the development efforts of optimized results.
Using logo to simplify page development
Web page developers are not all programmers who are familiar with scripting languages. The JavaServer page technology encapsulates a number of features that are needed to make dynamic content generation in an easy-to-use, JSP-related XML identity. The standard JSP identity is able to access and instantiate JavaBeans components, set or retrieve component properties, download applets, and perform features that are more difficult to encode and time consuming in other ways.
JSP technology can be extended by developing a customized identity library. In the future, third party developers and others can create their own identity libraries for common functions. This enables Web page developers to work with familiar tools and artifacts that perform specific functions like identities.

JSP technology is easily integrated into a variety of application architectures to leverage existing tools and techniques and to scale to support enterprise-class distributed applications. As part of the Java technology family and as part of the Java 2 (Enterprise Architecture), JSP technology can support highly complex web-based applications.
Because the built-in scripting language for JSP pages is based on the Java programming language, and all JSP pages are compiled into Java servlet,jsp pages, they have all the benefits of Java technology, including robust storage management and security.
As part of the Java platform, JSP has the Java programming language "once written, run everywhere" features. As more and more vendors add JSP support to their products, you can use the servers and tools of your choice, and changing tools or servers does not affect your current application.
When integrated with the Java 2 Platform, Enterprise (EE) and Enterprise JavaBean Technologies, JSP pages provide enterprise-class scalability and performance, which is necessary 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 components that the JSP engine can handle and extract. Typically, a JSP component creates text that inserts a final page.

Using the example is the best way to describe the JSP technology. The following JSP page is very simple: it prints the day with year, month, and is welcomed by the use of "Good Morning" and "Good Afternoon" based on time.

This page combines common HTML with a large number of JSP components.

Call to the clock JavaBeans component
Inclusion of an external file (for copyright information)
JSP Expressions and scripts
<HTML>
<%@ page language== "java" imports== "com.wombat.jsp.*"%>
<H1>Welcome</H1>

<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 the information is transferred to the JSP engine. In this example, the first line indicates the location of the extensions of some of the Java programming languages that will be accessed from the page. The instructions are set in the <%@ and%> tags.
Fixed template data: Identities that are not recognized by all JSP engines will be sent with the resulting page. Typically, these identities are HTML or XML identities. In the example above, there is no sequence table (UL) and H1 identification.
JSP actions or identities: these are usually implemented as standard or custom identities, and have the syntax for XML identities. In this example, the Jsp:usebean identifies the clock JavaBean on the server side of the instantiation.
An expression: The JSP engine calculates everything between the <%== and the%> tags. In the list item above, the day and year property values of the clock component (Clock) are returned as strings and inserted into the JSP file as output. In the example above, the first list item is the day and the second is the year.
Little feet are a small script that performs a function that is not supported by the identity or bundles all the things together. The built-in scripting language for JSP 1.0 software is based on the Java language. The small script in the example above determines whether it is now morning or afternoon and welcomes the user accordingly.
This example may be a little bit smaller, but technically not. Business can encapsulate critical processing in server-side components, and Web developers can easily access this information using familiar syntax and tools. Small java-based scripts provide a flexible way to perform other functions without requiring an extended scripting language. The page as a whole is readable and understandable, which makes it possible to find or prevent problems and
It's easier to share your work.
A portion of these components is described in more detail below.

JSP instructions

The JSP page uses a JSP to indicate that the instruction is passed to the JSP engine. This includes:

The JSP page indicates the information related to the delivery of the page, such as buffer and thread information or error handling.
The language indicates that the scripting language is specified, along with all extensions.
Contains instructions (shown in the example above) that can be used to include an external document in the page. A good example is a copyright document or a company information document?? It is easier to save the document in a centralized location and include it in the page than in the individual JSP pages. Of course, the included file may also be another JSP file.
The identity library indicates a customer identification library that the page can call.

JSP identification

Most JSP processing will be done through the xml-based identity associated with the JSP. JSP 1.0 contains a number of standard identities, which are identified as core identities including:

Jsp:usebean This identity declares the use of a JavaBeans component instance. If an instance of the component does not exist, the JavaBeans component instantiates and registers the identity.
Jsp:setproperty This identity sets the value of a property in an instance of a component.

Jsp:getproperty This identity gets the property value of an instance of a component, converts it to a string, and puts it into the implied object "out".

Jsp:include

Jsp:forward

  
The 1.1 version will contain more standard IDs.

The advantage of identity is that they are easy to use and share between applications. The real power of identity based syntax comes from the development of the Customer identity library, which enables tool vendors or other people to create and assign identities for specific requirements.

Script Components

JSP pages can include small scripts in the page, called Scriptlets. The Little Foot is a code fragment that is executed during the processing of the request. Small scripts can be combined with static components in a page (as in the example above) to create dynamically generated pages.

The script is described in the <% and%> flags. Everything in this pair of flags is executed by the script Description Language engine, in our case the Java Virtual machine on the host.

The JSP specification supports all commonly used scripting elements, including expressions and declarations.

Application Model of JSP page

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

JSP pages are usually compiled into the Java Servlet. The latter is a standard Java extension that is described in more detail at the www.java.sun.com site. Page developers have access to all of the Java application environments to take advantage of the extensibility and portability of Java technology.

When the JSP page is invoked for the first time, if it does not exist, it is compiled into a Java servlet class and stored in the server's memory. This allows for a very quick response to the next call to the page. (This avoids the problem of Cgi-bin generating a new process for each HTTP request, or the Run-time parsing caused by a server-side reference.) )

JSP pages can be included in a number of different application architectures or models. JSP pages can be used in a consortium of different protocols, components, and formats. The following sections describe some of the scenarios that might occur.

A simple application

In a simple implementation, the browser invokes the JSP page directly, and the JSP page generates the requested content itself (possibly invoking JDBC to get information directly from the database). JSP pages can invoke JDBC or Java Blendtm components to generate results and create standard HTML, which is sent back to the browser as a result.

  

This model basically replaces the Cgi-bin concept with JSP pages (compiled into the Java Servlet). This method has the following advantages:

Simple and fast programming
Page authors can easily generate dynamic content based on request and resource state
This structure works well for many applications, but cannot be extended to a large number of web-based concurrent customers accessing scarce enterprise resources because each customer must establish or share a connection to the available content resources. For example, if a JSP page accesses a database, many connections to the database may be generated, which affects the performance of the database.
A flexible application using the Java servlet

In another possible configuration, a web-based client might request the Java servlet directly, the servlet generates dynamic content, bundles the results into a result object, and invokes the JSP page. The JSP page accesses dynamic content from this object and sends the result (for example, HTML) back to the browser.

  

This approach creates more reusable components that can be shared between applications and can be done as part of a larger application. However, there are extensibility issues when dealing with the connection of enterprise resources, such as databases.

Scalable processing using enterprise-class JavaBean technology

JSP pages can also be an intermediary in an enterprise-class JavaBean (EJB) architecture. In this case, the JSP page and the back-end resource interact through the EJB component.

EJB components manage access to back-end 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 version (EE) platform.

Integration of JSP page and XML technology

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

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

JSP pages are not incompatible with XML tools. While Sun is designing JSP specifications so that JSP pages are easy to create for authors, even if they are manual, the JSP specification also provides a mechanism to create an XML version of any JSP page. In this way, XML tools can create and manipulate JSP pages.

By converting JSP identities and components into XML-compliant peers, you can use xml-based tools to manipulate JSP pages. For example, scripts can be included in <% and%>, or in <jsp:scriptlet> and </jsp:scriptlet> based on XML flags. In fact, it is possible to convert a JSP page into an XML page by following these simple steps, including:

Add a JSP root component
Convert symbols and instructions to XML-compliant peers
Create CDATA Components for other components on the page (usually non-JSP)
With this XML-compatible approach, designers who create HTML pages still have an easy-to-use environment for creating dynamic Web pages quickly, while xml-based tools and services can be integrated with JSP pages and work with JSP-compliant servers.
The future of JSP technology

JSP technology is designed to be an open, extensible standard for building dynamic Web pages. Developers can use JSP pages to create portable Web applications that run on different web and application servers for different scenarios, regardless of the creation tools that are appropriate for their situations and needs.

Through collaboration with industry leaders, Sun ensures that JSP specifications are open and portable. You can use any client and server platform 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 identity library for specialized functionality.

The 1.0 version of the JSP specification is the first step toward an open industry standard approach to Dynamic Web page generation. The 1.0 version forms the basis for a core identity set, an implied object, and the basic functionality required to start creating dynamic Web pages. There are already several Web servers, application servers and development tool vendors that are adding JSP1.0 support to their products, so that they already have initial, immediate support in the industry.

The 1.1 version to be completed later in 1999 will extend this version with more XML support, customized identification, and integration with Java EE. And vendors may selectively extend and expand the basic, essential functionality of the JSP specification. The JSP engine can strongly support multiple scripting languages and object models. While the industry expands and uses JSP technology capabilities, it also promises sun to ensure that JSP technology maintains inherent portability between platforms and servers.

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.