Develop web applications using JavaServer Pages2.0
Author Qusay H. Mahmoud July 2003
· JSP2.0
JSP2.0 provides some interesting new features compared to JSP1.2, making the web application designers and developers' life easier. The goal of JSP2.0 is to make JSP more easily, more importantly, using it without learning Java language. JSP2.0 simplifies the tag (TAG) API by joining the new extension mechanism of SimpleTag. In addition, there are some other improvements, the following is a new key feature introduced by JSP2.0. 1. Simple representation of language EL (Expression Language), which simplifies data accesses in JSP. It simplifies the code written based on JSP-based web applications, which can no longer use traditional Java scripts and Java expressions. 2. A new syntax of reusable custom behavior is defined, which is described by developers and page people in .tag and .tagx files. 3. XML syntax also has a substantial progress, joining new standard file name extensions (tag file .tagx and JSP file .jspx) This article will focus on the EL, simple tag API, and tag files. I believe that existing JSP developers will discover these new features very interesting and practical. · Why jump from 1.2 to 2.0
The version listed in JSR152 is 1.3. However, these new features that join will have a profound impact on the development model of JSP applications, so the expert group feels that as long as the primary version number is 2 to 2, it will reflect more appropriately. Of course, the new version number is also conducive to attracting new features to pay attention to new features. And the new 2.0 is fully compatible with the original version 1.2, and does not affect the original application. ·let's start!
In order to use JSP2.0, you need to support JSP 2.0 and servlet2.4 JSP containers. Jakarta Tomcat5.0 supports new JSP 2.0 and servlet2.4, you can download Tomcat or JWSDP1.2. · JSP Representation Language (EL)
Representing the language (EL) is designed for page personnel, which enhances JSP scope attributes to standard ways for business logic and JSP page information exchange. Note that although EL is a key aspect of JSP2.0, it is not a usual programming language, which is just a simple data access language, and its appearance is to facilitate access to the value of the expression in the scripting language and the request. The data. Before JSP2.0, the page personnel must use the expression <% = aname%> to access the system, as the following example: You can use three forms of access to application data: objects of the object, use "." Operator or use of array elements in parentheses "[Name]". Expression $ {data} represents the scope variable DATA. You can obtain properties from the aggregation by using a period "." Or parentheses "[]" operator. 1. The period operator is used to get a named property. For example, the expression is $ {Customer.Name} represents the Name property in the Customer domain. 2. Bracket operators can also be used to get naming properties, such as $ {Customer ["name"]}. It can also use the index access attribute, $ {Customer [0]} represents the first element in the Customer collection. Indicates that the language will be treated uniformly. Therefore, $ {Customer.Name} and $ {Customer ["name]"} "} It is true that all EL use $ {and}. EL uses PageContext.FindAttribute (String) Query properties, returns null values if the property does not exist. · Operator EL supports arithmetic, relationships, and logical operators, and there is also a special operator to determine if the object is empty. The operator is listed in Table 1. You can use the EMPTY operator to determine if a gathering or string is empty or NULL. For example, $ {empty param.name} is true only if the request parameter named param does not exist. The EMPTY operator can be used in combination with "!", Like $ {! Empty param.name} is true if param exists. Table 1: EL operator Operator description plus - Less * Multiply / or DIV except % or mod Output (surplus) == OR = equal ! = OR! = not equal to Be less than > or gt more than the <= or le no greater than > = OR GE not less than && or and Logic || OR OR Logic or OR NOT Logical EMPTY Check if a? b: c Conditional statements · Implicit object In addition to the operator, EL also defines a series of implicit objects to support access to application data. Implied object definitions such as Table 2 Table 2: Implied objects provided by EL Include object content ApplicationsCope Application domain variable collection cookie Collection of all cookies HEADER HTTP request head string HEADERVALUES HTTP request head string collection Initparam Application initial parameter collection PageContext Javax.servlet.jsp.pageContext object PageScope Table area variable collection PARAM Request parameter string Paramvalues Request parameter string Requestscope Collection of request domain objects Sessionscope Collection of session domain objects · EL example Web Pages can use EL development on the basis of Java. Example of adding Include objects, $ param [var] can be used to read data in the table. See form.jsp code Code Sample 1: form.jsp