Basic use of Jstl

Source: Internet
Author: User

<body>
<%
Request.setattribute ("name", "lisi123");
Request.setattribute ("TTT", New ArrayList ());
Request.setattribute ("template", "%>
<!--
Value: The values to display
EscapeXML: Whether to translate HTML tags true|false
Default: Defaults worth value is null when displaying default values can also be written between label bodies the contents of the default and tag bodies cannot be present at the same time


Note: The most common way is the EL expression


-
<c:out value= "${ttt}" Escapexml= "false" >123</c:out><br>
${template}

${empty TTT}
<!--
In El expression + denotes the meaning of sums


-
${"1" + "2"}
<%--${"A" + "B"}--%>
</body>

TESTSET.JSP:

<body>

<%!

public static Class users{

private String name;

Public String GetName () {
return this.name;
}

public void SetName (String name) {
THIS.name = name;
}
}


%>
<!--
Scope: If not specified, default to the scope given in the page scope without a scope end

Value: The values stored

var: the stored variable

Target: The object to change

Property: The attribute in the object that you want to change

Common ways
Value+var+scope
Value+target+property
-

<%
Users u = new users ();
U.setname ("Zhangsan");
Request.setattribute ("User", u);
%>
<crazy:set scope= "Request" value= "testset123" var= "Testset" ></crazy:set>
<crazy:set scope= "page" value= "testset123456" var= "Testset" ></crazy:set>
${requestscope.testset}
${user.name}

<crazy:set property= "name" value= "Lisi" target= "${user}" ></crazy:set>
${user.name}


<!--
If you do not specify a scope, the value of the corresponding name in all scopes is removed

-
<crazy:remove var= "Testset" scope= "page"/>
${testset}
</body>

TESTIF.JSP:

<body>
<c:set value= "one" var= "num" scope= "request" ></c:set>
<c:if test= "${param.num>10}" var= "Flag" scope= "page" >
&LT;H1 style= "color:red" >num greater than 10</c:if>
<c:if test= "${!flag}" >
&LT;H1 style= "Color:green" >num not much more than 10</c:if>



<!--
if () {

}else if () {

}else{

}


else{

}if () {

}else{

}else[

}

-
<c:choose>
<c:when test= "${param.num>10 && param.num<20}" >

<c:when test= "${param.num>20 && param.num<50}" >

<c:when test= "${param.num<10}" >

&LT;C:OTHERWISE&GT;&LT;H1 style= "color:red" >num &gt; 50</c:choose>
</body>

TESTFOREACH.JSP:

<body>
<%
list<string> list = new arraylist<string> ();
for (int i=0;i<20;i++) {
List.add ("list" +i);
}
Request.setattribute ("list", list);
%>
<!--
Foreach


Items: Collections to loop
var: variable for each time of the loop
Step: Stepper or interval
Begin: From which subscript element begins
End: at which subscript element ends

-

<c:foreach items= "${list}" var= "L" step= "2" begin= "0" end= "ten" varstatus= "S" >
<span>${l}</span>|:| <span>${s.current}|${s.index}|${s.count}|${s.first}|${s.last}</span><br>
</c:forEach>
</body>

Basic use of Jstl

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.