Jsp --- JSTL core tag

Source: Internet
Author: User

The <% @ taglib %> command must be used to format tags on the JSP page,
 
<% @ Taglib prefex = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
 
<C: set> A tag can store variables in a JSP range or a JavaBean attribute.
 
Five formats are available:
 
1, <c: set var = "username" value = "value"> </c: set> // specify the variable name and value.
 
2, <c: set var = "username" value = "value" scope = "page | request | session | application"> </c: set> Save the value to the variable whose range is scope.
 
3, <c: set var = "username" scope = "page | request | session | application">
 
Text Content
 
</C: set> store text content data to a variable in the scope.
 
4. <c: set value = "value" target = "target" property = "propertyName"> </c: set> stores the value in the properties of the target object.
 
5, <c: settarget = "target" property = "propertyName">
 
Text Content
 
</C: set> store text content data to the properties of the target object.
 
<C: out> labels are used to display data content. There are four format syntaxes.
 
1, <c: out value = "value"> </c: out> use the value attribute to specify the value to be displayed.
 
2. <c: out value = "value" escapeXml = "true | false"> </c: out> whether to output the content in the value as is
 
3. <c: out value = "value" default = "No Data"> </c: out> use the Default attribute to set the default value.
 
4, <c: out value = "value" escapeXml = "true | false">
 
Text Content
 
</C: out> set the default value through text content
 
<C: remove> used to remove a variable from a specified range.
 
<C: remove var = "number" scope = "session">
 
01
<% @ Page language = "java" contentType = "text/html; charset = gb2312" %>
02
<% @ Taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
03
<! DOCTYPE html>
04
<Html>
05
<Head>
06
<Title> Use of the remove tag </title>
07
</Head>
08
<Body>
09
<H1> Use of the remove tag 10
<Hr/>
11
<% -- Add variable number, stored in page range -- %>
12
<C: set var = "number" value = "$ {1 + 2}" scope = "page"/>
13
<% -- Output variable -- %>
14
Number: <c: out value = "$ {pagination. number}" default = "No Data"/>
15
<% -- Remove the number variable in the page range -- %>
16
<C: remove var = "number" scope = "page"/>
17
<% -- Output variable -- %>
18
Number: <c: out value = "$ {pagination. number}" default = "No Data"/>
19
</Body>
20
</Html>
<C: if> labels are used for process control.
<C: if> A tag can be in either of the following formats:
 
1. <c: if test = "condition" var = "varName" [scope = "{page | request | session | application}"]/>
 
2. <c: if test = "condition" var = "varName" [scope = "{page | request | session | application}"]> body content </c: if>
 
<C: choose> <c: when> <c: otherwise> label
 
01
<% @ Page language = "java" contentType = "text/html; charset = gb2312" %>
02
<% @ Taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
03
<! DOCTYPE html>
04
<Html>
05
<Head>
06
<Title> Use of Choose labels </title>
07
</Head>
08
<Body>
09
<H1> use of the Choose tag 10
<Hr/>
11
<C: choose>
12
<C: when test = "$ {4 <6}">
13
<C: out value = "Yes"/>
14
</C: when>
15
<C: otherwise>
16
<C: out value = "No"/>
17
</C: otherwise>
18
</C: choose>
19
</Body>
20
</Html>
<C: forEach> label
A member used to traverse a collection object.
 
<C: forEach [var = "username"] items = "collection" [varStatus = "varStatusName"] [begin = "begin"] [end = "end"] [step = "step" ]>
 
Local content
 
</C: forEach>
 
One is used to set the number of times the statement is executed cyclically.
 
<C: forEach [var = "username"] [varStatus = "varStatusName"] [begin = "begin"] [end = "end"] [step = "step"]>
 
Local content
 
</C: forEach>
 
<C: forTokens> tag used to separate strings based on specified delimiters
 
<C: forTokens [var = "varname"] items = "stringOfTokens" delims = "delimiters" [varStatus = "varStatusName"] [begin = "begin"] [end = "end"] [step = "step"]>
 
Local content
 
</C: forEach>
 
<C: import> tag, which can include static or dynamic files to its own JSP webpage
 
<C: import url = "url" [context = "context"] [var = "varname"] [scope = "{page | request | session | application}"] [charEncoding = "charEncoding "]>
 
Local content
 
</C: import>
 
<C: param> label used to pass Parameters
 
<C: url> tag used to generate a URL
 
Without Parameters
 
<C: url value = "value" [context = "context"] [var = "varname"] [scope = "{page | request | session | application}"]/>
 
Parameters
 
<C: url = "url" [context = "context"] [var = "varname"] [scope = "{page | request | session | application}"]>
 
<C: param/> label
 
</C: url>
 
<C: redirect> tag, which can jump from one JSP page to another.
 
Without Parameters
 
<C: redirect url = "url" [context = "context"]/>
 
Parameters
 
<C: redirect url = "url" [context = "context"]>
 
<C: param/> label
 
</C: redirect>


From Zhang Dapeng's blog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.