1. The Java Server Pages standard Tag Library (JSTL) contains a variety of tags available for use in JSP pages
JSTL Advantages:
- Provides a standard set of labels
- Can be used to write various dynamic JSP pages
- Users access databases, conditionally execute code and support internationalization
2. Core Tag Library
- Universal tags [scope variables within JSP pages] set remove out
- conditional tags [various conditions in the JSP page] if choose
- Iteration Labels
3. For example:
(1) by label
// insert directives that use universal labels
<% @ taglib uri=http://java.sun.com/jstl/core_rt prefix= "C"%>
<body>
<c:set var= "Example" Value= "${100+1}" scope= "Session"/>
set label for setting values and scopes for variables
<c:out value= "${example}"/>
The result of the Out label display value
<c:remove var= "Example" scope= "Session"/>
//remove tag to delete a variable with scope
</body>
Case:
• Use common tags in JSP pages set, out, and remove tags
< Body >
<H1> Welcome to Shopstop
The JSP page stores sessionvariable in a variable within a session scope, and other JSP pages in the WEB application can access this variable. <c:set var = "sessionvariable" value= "${90+1}" scope= "session"/>//display its value before deleting sessionvariable: <c:out value= " ${sessionvariable} "/> <c:remove var=" sessionvariable} "scope=" Session "/> </br> display and delete sessionvariabl The value of E. <br/> <c:out var= "${sessionvariable}" >//sessionvariable value is null
</body>
(2) Condition label
Case:
< Body >
<c:if test= "${pagescope.signalstrength<5}" >
<c:set var= "Signalfailure" value= "true" scope= "page"/>
</c:if>
<c:choose>
<c:when test= "${pagescope.signalfailure = = true}" >
Signal Disconnect </c:when> <c:otherwise> signal Open </c:otherwise>
</c:choose>
</body>
<C:choose> <C:whenTest= "${empty param.username}">Nnknown user. </C:when> <C:whenTest= "${param.username== ' Tom '}">${param.username} is manager. </C:when> <c:otherwise>${param.username} is employee. </c:otherwise> </C:choose>The above tag is equivalent to the following Java program fragment:<% Stringusername=Request.getparameter ("username"); if(username==NULL){ //corresponds to the first<C:when>the body of the label Out.print ("nnknown user."); }Else if(Username.equals ("Tom")){ //corresponds to a second<C:when>the body of the label Out.print (username+"is Manager."); }Else{ //corresponding<c:otherwise>the body of the label Out.print (username+"is employee."); } %>
(3) Iteration label
Case:
JSTL Standard Tag Library