Java standard tag Library (JSTL)
JSTL (Java Standard Tag Library)-Java Standard Tag LibraryJSTL composition:JSTL-Core tag library. -This is the focus of this part.
JSTL-I18N-International tag library. Internationalization-I18N
JSTL-SQL-database operation label (unlike the MVC design mode ).
JSTL-Functions-function library.
JSTL-XML: XML operations (same as SQL labels ). In the jstl-1.2.jar directory of the META-INF package, versions of various tld files are saved. See.
Use JSTL core labels:
If your Web project is based on JavaEE2.5 or later. You can use the JSTL core tag library through the <% @ taglib command on any page of your project.
<% @ Taglib uri = http://java.sun.com/jsp/jstl/core prefix = c %>
A uri is a resource identifier that references the tag library and does not represent an actual address.
Prefix is a custom Prefix.
If your project is a project below JavaEE2.5, the following two jar files must exist in the lib directory of your project:
Jstl. jar, standard. jar
Specific Use: JSTL-Core contains the following sub-tags: $ {Name} output tag
PageContext. setAttirbute (key, value, scope); declare tags
C: remove delete data in a certain category
Judge c: else, c: elsfif
Determine the Branch c: if, c: else if c:
Traversal
Separate
Importing other resources is equivalent to dynamically including sharing the same request
-Rewrite the url
Redirect response. sendRedirect (''..)
The following describes the specific operations:
Output results on the page.
-Output the name value in the request.
-Output parameters to the page.
Search from page to application. If not found, the default value "hello" is displayed.
Another way to set the default value is as follows:
Default-value-Default value.
The default value is output only when the required information is null or does not exist.
ExcapeXml property: the default value is true, which is used to convert html and other tags to <and other conversion elements. Example:
<% String name = Red; pageContext. setAttribute (name, name); %>
Do not convert xml or html and output it directly. In this way, Red characters are displayed on the page because the browser parses html data.
<% PageContext. setAttribute (name, jack_P); request. setAttribute (name, jack_R); request. setAttribute (name2, hello, China); % >$ {name} // search from small to large
------- Output tag
$ {Name2} can parse the html language
------- The html language cannot be parsed and output as is
Labels are used as follows:
Set the value for the name variable of the String type.
Retrieve the data directly from the parameter and assign a value to the name.
If the variable is JavaBean, set the value for this JavaBean attribute.
Example:
If the variable is Map, set the value for the key in Map.
, For example:
Set the value for the name variable of the String type.
Retrieve the data directly from the parameter and assign a value to the name.
If the variable is JavaBean, set the value for this JavaBean attribute.
Example:
If the variable is Map, set the value for the key in Map.
, For example:
$ {}
$ {RequestScope.}
It is used to implement the if statement in Java. Its syntax is as follows:
Example:
Output this line when the value of name is Jack
The above judgment is equivalent to the following code snippet:
If (pageContext. getAttribute ("name ")! = Null &&!.. Equals ("Jack ")){
Out. println ("...");
}
25} var = aa> bigger than 25 !! Smaller than 25 !!
Choose, when, otherwise
These labels can be used together to implement if... Else statement.
The user does not enter the name parameter
$ {Param. name} is the administrator.
User: $ {param. name}
When using c: when, you must follow the following syntax rules:
And It cannot be used independently. It must be located in Must be located after c: when.
20}> greater than 20 !! 10}> greater than 10 !! 0}> less than 10 !! This is another one...
Remove a tag
Aaa $ {requestScope.}
Iteration tag
ForEach is used to traverse objects in a set.
Basic Syntax:
Iteration part
For forEach, The begin (start index), end (end index), and step attributes are as follows:
... Output 810
$ {X}
<% String [] a = {Xiao Wang, Xiao Ming, Xiao Yang, Xin Ge}; request. setAttribute (a, a); %> $ {I}
<% List
List = new ArrayList
(); List. add (123a); list. add (123d); list. add (123b); list. add (123c); list. add (123e); list. add (new brother); session. setAttribute (list, list); // use the el expression to obtain the parameter %>
$ {Li}
<% // Demonstrate that map uses the el expression Map
Map = new HashMap
(); // Store map with hash values. put (aa, 123); map. put (cc, 567); map. put (bb, 345); map. put (dd, 789); application. setAttribute (map, map); %>
$ {Mm. key }$ {mm. value }$ {idx. index }$ {idx. count}
Split the characters in XX format
$ {X}