Core Tag Library
Reference:
<%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>
It is the core library in Jstl, providing common support for everyday tasks, such as displaying and setting variables, reusing a set of items, testing conditions, and other actions such as importing and redirecting Web content. Core tags can be divided into 4 types by function:
1 Variable Maintenance:
(1) <c:set>: Sets variable values and object properties. The syntax is as follows:
<c:set value= "value" var= "variable name" scope= "Variable Scope" target= "Object Name" property= "object property name" ></c:set>
Each setting has two ways, summed up in 4 forms of,<c:set>, as follows:
A. Setting JSP variables with tag properties
<c:set value= "value" var= "variable name" scope= "Scope"/>
B. Setting a JSP variable with a tag body
<c:set var= "variable name" scope= "Scope" > Tagged content </c:set>
C. Setting object properties with Tag properties
<c:set value= "variable name" target= "Object Name" property= "object property name"/>
D. Setting object properties using the marker body
<c:set target= "Object name" property= "Scope" > Tagged content </set>
(2) <c:remove>: Deletes a variable at the specified scope. The syntax is as follows:
<c:remove var= "variable name" scope= "Scope"/>
2 Process Control: divided into conditional tags and iteration labels.
Condition tags:<c:if> <c:choose> <c:when> <c:otherwise>
(1) <c:if>: The use of the IF statement in the Java language is the same as, but does not implement else functionality.
The <c:if> tag has two grammatical forms, which are distinguished by the unmarked body.
No label body:
<c:if test= "test condition" var= "variable name" [scope= "Scope"]/>
Tagged Body:
<c:if test= "test condition" var= "variable name" [scope= "Scope"]>
Label body
</c:if>
<c:if> with tagged body
<c:if test= "${user.visitcount!=0}" > Welcome </c:if>
(2) <c:choose> <c:when> <c:otherwise>
<c:when> <c:otherwise> cannot be used alone and can only be used as a sub-label for <c:choose>. These three tags combine to implement the switch statement functionality in Java. The syntax is as follows:
<c:choose>
<c:when test= "${user.class== ' guest '}" >
Label Body 1
</c:when>
<c:when test= "${user.class== ' VIP '}" >
Label Body 2
</c:when>
<c:otherwise>
Label Body 3
</c:otherwise>
</c:choose>
Iterate tags:<c:foreach> <c:forTokens>
(1) <c:foreach>: Used to traverse a collection of objects.
<c:foreach var= "variable name" items= "collection" varstatus= "Traversal state name"
begin= "Begin" end= "End" step= "Step" >
Label body
</c:forEach>
(2) <c:fortokens>: Used to iterate through a string, and each time a traversal result returns a word in a string.
<c:fortokens items= "string" delims= "delimiter" var= "variable name"
varstatus= "Traversal state name" begin= "Begin" end= "End" step= "Sep" >
Label body
</c:forTokens>
3 URL Management
(1) <c:url>: Used to encode the URL address.
Tagged Body:
<c:url value= "url" context= "path" var= "variable name" scope= "Scope" >
Label body
</c:url>
The following code:
<c:url value= "http://localhost:8080/el/index.jsp" var= "Newurl" >
<c:param name= "name" value= "zero"/>
<c:param name= "age" value= "/>"
</c:url>
<a href= "${newurl}" > Point me </a>
The generated url:http://localhost:8080/el/index.jsp?name=zero&age=28
No tag body: used primarily for editing context URLs.
<c:url value= "url" context= "path" var= "variable name" scope= "Scope"/>
The following code:
<c:url value= "/logon.jsp" > Login </c:url>
If the current path is El, the output is:/el/logon.jsp
(2) <c:import>: Introduces a URL resource to the current JSP page (which can be a resource on a remote program site). The include directive and the include action do not introduce resources other than web programs to JSP pages, and the imported resources must be in the current Web program.
Syntax introduced as a string object:
<c:import url= "Address" context= "Context path" var= "variable name"
Scope= "Scope" charencoding= "character Set" >
Label Body Use <c:param>
</c:import>
The following code: introduce an external resource into the current JSP page.
<c:import url= "http://www.hao123.com" var= "Myurl" charencoding= "gb2312" >
</c:import>
<a href= "${myurl}" > Address </a>
Syntax to import with the reader object:
<c:import url= "Address" context= "Context path" varreader= "variable name"
Scope= "Scope" charencoding= "character Set" >
Tag body uses other action elements
</c:import>
(3) <c:redirect>: For HTTP redirection.
No label body:
<c:redirect url= "Address" context= "Context path"/>
Tagged Body:
<c:redirect url= "Address" context= "Contextual path" >
<c:param/> tags
</c:redirect>
(4) <c:param>: can only be embedded in the <c:url>,, <c:import>, <c:redirect> tags as child elements to use. This label is used primarily to set the parameters that will be passed in the URL.
No label body:
<c:param name= "name" value= "value"/>
Tagged Body:
<c:param name= "name" value= "Value" >
Label body
</c:param>
4 other tags:<c:out>, <c:catch>.
(1) <c:out>: Displays variable contents in a JSP page.
No label body:
<c:out value= "value" escapexml= "{true|false}" default= "Default"/>
Tagged Body:
<c:out value= "value" escapexml= "{true|false}" default= "Default Value" >
Label body
</c:out>
which
Default: Used to specify the value that should be output when the value of value is null.
EscapeXML: Used to set whether <, >, &, ', ', ', ', ', ', or ' are escaped.
The EscapeXML default is true, which indicates that the conversion occurred.
"<" converted to "<"
">" Converted to ">"
"&" converted to "&"
"'" Converted to "& #039"
"" "Convert to" & #034 "
(2) <c:catch>: Used to handle JSP page errors.
If the JSP page is faulted, you can go to the error handling page by setting the page directive property. The <c:catch> tag is a supplement to this error handling. It is handled by embedding the JSP code fragment that may have an exception in the tag body, and then using the var attribute to get the exception that is thrown by the receiving tag body.
<c:catch var= "variable name" >
Nested actions
</c:catch>
How to use:
<c:catch var= "MyException" >
Nested actions
</c:catch>
<c:if test= "${myexception!=null}" >
Content
</c:if>
The C tag in the JSP