JSTL (JSP Standard Tag Library) Introduction Author: Let Master (
Shaoye@dev-club.com
The foremail starts from the JSP 1.1 specification, JSP supports using custom labels in JSP, custom labels, have caused programmers to repeat the definition, which has contributed to the birth of JSTL (JavaServer Pages Standard Tag Library). Because JSTL needs to be used in the work, but the Internet can't find Chinese information about JSTL, so there is this article. JSTL Introduction JSTL is a JSP label library that is constantly open source code, which is maintained by the Jakarta team of Apache. JSTL can only run on a container that supports JSP1.2 and Servlet2.3 specification, such as Tomcat 4.x. But in JSP 2.0, it is standard for standard support. JSTL currently has a current version of 1.02, and finally published version 1.0. JSTL contains two parts: tag libraries and EL (Expression Language Expression Language) languages. The label library currently supports four labels:
Label URI prefix sample Corehttp: //java.sun.com/jstl/corec
Core supports some basic operations in JSP; XML Processing supports processing of XML documents; I18N Capable Formatting supports internationalization of JSP pages; Database Access (SQL) supports JSP's operations of the database. Since I have limited level, this article only introduces the Core tag, if you are interested, you can explore the use and expansion of other three labels. EL Language Introduction The EL language is a representation of a JSTL output (input) a Java expression. In JSTL, the EL language can only be used in attribute values. The EL language can only be called by establishing an expression $ {exp1}. There are three ways to use expressions in attribute values. 1. The Value property contains an expression
Digital operators and logical operators are the same as Java language, no longer list. Core Tag Library 1, General Tags
The selection must default to the value value output information, which can be the EL expression or constant is no default value as an empty display message whether there is no escapexml to avoid special XML characters. TRUE
example:
Your username is:
Specifies to get the value of UserName from the session;
The value of the username is displayed, and the default is taken from the request (page). If there is no user named username in the requestion, it is taken from the session, and the session is not taken from Application (servletContext). If no value is not taken, no value display.
Attribute Description Must default value value to save information, you can be an EL expression or a Target that needs to modify the variable name of the attribute. Generally, no Property needs to modify the JavaBean property No Var need to save information variable No No Scope Saves Variables Wid Over the Variables
If the Target property is specified, the property property must also be specified. example:
Save the value of Test.Testinfo into the session Test2, where Test is an instance of a JavaBean, and Testinfo is the properties of the Test object.
Save the value of the Cust.Address of the object Cust.Address to the Variable City
A selection is a variable that must be default VAR to delete the variable that does not have the scope to be deleted. All ranges, including Page, Request, Session, Application et al.
example:
Remove Test2 variables from the session. 2, stream control tag
This is a class that must be default the conditions that require the evaluation of TEST, which is equivalent to the condition in the if (...) {} statement is the variable number of the VAR requires the saving condition results. No Scope save condition results.
Conditions if you must default, it is necessary to evaluate the conditions for TEST.
If the user.wealthy value True, User.wealthy is true is displayed.
The subsequent items that must be default Items to loop-looped items No Begin Start Condition No 0nd End Condition No Collection The last item STEP Step Length 1var Represents the current item variable name No Varstatus display loop state variable
example:
Equivalent to the Java statement
For (int i = 0; i Here, Vectors is a Java.util.Vector object, which is stored in String data, and Vector is the String object under the current cycle. In fact, the VECTORS here can be any object that implements the java.util. Collection interface. Output: count = 0 ... count = 100 The property description must default Items to loop-free items that is not a Delims split. No Begin Start Condition No 0nd End Condition No Collection The last item STEP Step No 1var Represents the current item variable name No Varstatus display loop status None example The use of this label is equivalent to the Java.util.StringTokenizer class. Here, the string A: B: C: D is followed by: Separate loop four times, token is a string that is looped to the currently split. 4. Import files and urljstl core tag libraries Support to use Attribute Description Must default The URLURL address is whether the name without context / after the name of the local web application is whether the current application Charencoding is used to import data whether ISO-8859-1VAR accepts the processed URL variable name, the variable storage URL No Output to the page scope storage URL variable number of variables to the variable number of variables example: Contain URL http://www.url.com/edit.js to the current location of the current page and save the URL to the newsfeed variable Output in the current position of the current page Output A selection is a default value URLURL address is whether the name without context / back to the local web application is currently available. example: The request will be reset to http://www.yourname.com/login.jsp page, which is equivalent to response.setRedirect ("http://www.yourname.com/login.jsp"); A selection of sexy means that the value of the variable name set in the request parameter is not valued in the request parameter is not set. example: Pass the parameter 888 with the name to the login.jsp page, which is equivalent to the advantage of login.jsp? Id = 888JSTL 1. Provide a consistent interface between the application server, and maximize the web application in each application server. The transplantation between. 2, simplify the development of JSP and web applications. 3. Reduce the number of Scriptlet code in JSP in a unified manner, which can achieve programs without any Scriptlet code. In our company's project is not allowed to have any scriptlet code appear in JSP. 4, allowing JSP design tools to develop further integration with web applications. I believe that there will soon support the iDE development tools that support JSTL. Summary The above is only part of JSTL, if there is time, I will continue to write other parts to everyone. If you want to use JSTL, you must put JSTL.jar and Standard.jar files in ClassPath, if you need to use the XML Processing and Database Access (SQL) tab, put the related JAR files in ClassPath, these JAR files All exist in the Zip file downloaded back. This zip file can be from http://jakarta.apache.org/builds/jakarta-taglibs/releases/standard/jakarta-taglibs-standard-1.0.zip download. Reference 1, http://java.sun.com/products/jsp/JSTL/ Sun's JSTL site 2, Http://jakarta.apache.org/taglibs/doc/standard-doc/intro.html JAKARTA group of JSTL sites 3, http://www.manning.com/bayern/appendixa.pdf JSTL's reference documentation, many of this article is translated from this PDF file. 4, << J2EE Programming Guide (1.3 Edition) >> Introduced JSTL's prototype, Wrox book is a boutique.
c: foreach>