Web page technology review (including FASTM)

zhaozj2021-02-12  129

Web page technology review (including FASTM)

Order

In the Java Web Application, the page build part is the most cumbersome part of the headache.

Other layers can be well structured, and only the structure of the page generated part is very disabled.

This article first introduces and compares various page generation techniques, and then specifically describes a PHP template to improve the PHP template to Java's open source project - FASTM.

I hope that FASTM can help the majority of Java Web programmers will be freed from cumbersome page development work.

2. Page Generation Technology Summary

The page referred to herein is a web page that can be displayed in the browser in XML, HTML, WML, and the like.

According to the location of the page processing logic, page generation technology can be divided into two categories:

(1) A class is that the page itself contains logic (IF, For, etc). For example, JSP Taglib, Velocity, XML XSLT (Processing Logic is in the XSL file), TapeStry, etc.

In this type of technology, since the page itself contains logic, the structure and reusability of page components are not very good, and "object", "class", "package", etc. are unable to use object-oriented features.

(2) Another class is that the page itself does not contain logic. For example, Echo, XMLC, DOM XPath, Echo, PHP, JDynamicte, FASTM, etc.

In this type of technology, due to the processing logic in Java Code, how much is the structure and reusability of the Java program, how good the structure and reusability of page components can be.

The following is a separately explained and compare these page generation techniques:

2.1. JSP Taglib

JSP Taglib is Sun's page generation technology specification.

advantage:

The authority, normative, many users, the third party provides a lot of Taglib support.

Moreover, JSP is essentially a servlet. The Java Code part is very powerful and flexible and can achieve the greatest flexibility in Java language.

Taglib can reach a certain level of page elements reuse. Taglib can also help the Java Code "contamination" section of the JSP page to some extent. J

Disadvantages:

The disadvantage of JSP is obvious. Java Code and HTML pages are mixed together, which is the top Java Code Pollution problem that makes the majority of programmers. This is not fully solved using Taglib.

Moreover, programmers and page editors cannot work on the same file. Each page editor has a html page, and the programmer must re-join Java Code and Taglib.

Once Java Code and Taglib are added, the HTML page cannot be displayed correctly in the page editor (Dream Weaver, Front Page). If the program does not run, you can't see the page structure of the JSP page, display style and content.

About efficiency, flexibility, structural, reusability, JSP Taglib are a two difficult option.

A large number of Taglibs in JSP can make JSP's page structure, more in line with XML format, and can reuse some page elements. But the code after Taglib is huge and messy, and the operating efficiency is very low, which seriously affects the response speed. Tablib is very unflexible, and things that can be completed are limited. The reusability of Tablib code itself is limited by the Tagsupport definition, not very good. Taglib's writing is not a pleasant thing. J If you use Java Code in JSP, then the structure of the page will be poor and difficult to manage. All the code is in the same file, which is a big HTML page, which is simply like a nightmare. From a left bracket "{" to find the corresponding right bracket "}" to become a painful thing. The HTML element in the middle of the Java Code cannot be reused. So, in addition to include file or jsp: include, JAVA Code in JSP does not have reusable.

2.2. Velocity

http://jakarta.apache.org/Velocity/

Velocity is a template processing tool. The Velocity Template is composed of some Velocity scripting languages ​​or variable definitions in HTML.

advantage:

Velocity's script language (start) or variable definition (with $ markers) and HTML, WML, XML, etc. are not conflict.

Simple Velocity page (excluding branches and loop logic) can be displayed correctly in the page editor (Dream Weaver, Front Page).

Disadvantages:

Similarly, the page processing logic of the Velocity Template is mixed together with HTML elements. If the logical complex logic of the Velocity page (such as loop and judgment branch), then the Velocity page cannot be displayed correctly in the page editor.

In the event of a big HTML page, find the corresponding "#end" from a "#IF" is also a very painful thing. The HTML element in the middle of the Velocity script language cannot be reused. Therefore, the script code and HTML elements in the Velocity template do not have reusability (except for include file).

2.3. XML XSLT

http://cocoon.apache.org/

The Cocoon project uses XML XSLT methods. The Java program only needs to output XML data, and the Cocoon Framework calls the XSL file to convert XML data into files such as HTML, WML.

advantage:

The programmer has provisions, do not consider the page structure and display mode, just output XML data.

With the same XML data, as long as different XSL files are defined, you can easily have different display-free pages.

In terms of content and display style separation, XML XSLT this method is best.

Disadvantages:

slow. XSLT is slow.

Since there is no HTML file, you can't see the page structure, display style and content. Only after the program runs, after XSLT conversion,

XSL syntax is more difficult to master, because there is no "ready" editing tool, high learning costs, far more than HTML learning costs.

2.4. Tapestry

http://jakarta.apache.org/tapestry/

TapeStry extends the definition of HTML elements. TapeStry uses these extended HTML element properties to represent processing logic (cyclic, branch, etc.), component definitions, and variable definitions.

advantage:

The entire TapeStry page file is HTML element, which can be displayed in the page editor (Dream Weaver, Front Page). However, whether the display is correct, it is another matter, and the complexity of processing logic (cycle, branch, etc.) is associated. It is similar to Velocity. TapeStry's page component reuse is relatively high.

Disadvantages:

complex. Tapestry definitions and usage are complicated. Slow due to complexity.

I don't actually use Tapestry's specific experience, this will not continue to comment. J

2.5. XMLC

http://xmlc.enhydra.org/

XMLC compiles HTML, WML and other documents into a DOM structure of Java classes. The programmer does not need to take a point, just operate this DOM structure, you can dynamically generate a page.

XMLC generates the operation method of the corresponding node based on the ID definition of the HTML element.

advantage:

The page is pure HTML without any logic. Correctly displayed in the page editor (Dream Weaver, Front Page).

Java Code handles DOM structure, code structure, and reusability. The DOM node is HTML element, that is, page components, also have a good reusability, you can place a DOM node in any of any documents at any time.

Because it is static compile, there is no dynamic analysis process, and the speed of the document is very fast.

Disadvantages:

Each time you modify the HTML page, you must re-compile the HTML file into a Java file. Moreover, many HTMLs are not a good XML structure, and it is not possible to compile it to a DOM structure.

The DOM structure cannot be reused in a multi-threaded environment, which means that each page request needs to generate a separate DOM structure, which is relatively large. Moreover, each DOM structure is used, it is difficult to empty and reset it, it is difficult to provide the next request. When the HTML file is relatively large, the overhead of the memory is significantly increased.

XMLC is not flexible enough. For example, we know, many Java Scri

PT

Method is defined in XML annotation. such as: