首页 技术 正文
技术 2022年11月11日
0 收藏 762 点赞 3,440 浏览 2155 个字

JSTL的基本使用

<body>
<%
request.setAttribute(“name”, “lisi123”);
request.setAttribute(“ttt”, new ArrayList());
request.setAttribute(“template”, “<h1>lisi123</h1>”);
%>
<!–
value:要显示的值
escapeXml:是否转译html标签 true|false
default:默认值 当value的值为null的时候 显示 默认值也可以写在标签体之间 default 和标签体之间的内容不能同时存在

注意 : 最常用的方式是 el表达式

–>
<c:out value=”${ttt }” escapeXml=”false”>123</c:out><br>
${template }

${empty ttt }
<!–
在el表达式中 + 表示加和的意思

–>
${“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:如果不指定 则默认放到 page作用域中 给定的作用域没有scope结尾

value:存放的值

var:存放的变量

target:要更改的那一个对象

property:要更改的那一个对象中的那一个属性

常用方式
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 }
<hr>
${user.name }

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

<hr>

<!–
如果 不指定作用域 会将所有作用域中对应名称的值 一除掉

–>
<crazy:remove var=”testset” scope=”page”/>
${testset }
</body>

testif.jsp:

<body>
<c:set value=”11″ var=”num” scope=”request”></c:set>
<c:if test=”${param.num>10 }” var=”flag” scope=”page”>
<h1 style=”color:red”>num大于10</h1>
</c:if>
<c:if test=”${!flag}”>
<h1 style=”color:green”>num不大于10</h1>
</c:if>

<hr>

<!–
if(){

}else if(){

}else{

}

else{

}if(){

}else{

}else[

}

–>
<c:choose>
<c:when test=”${param.num>10 && param.num<20 }”><h1 style=”color:red”>10 &lt; num &lt; 20</h1></c:when>
<c:when test=”${param.num>20 && param.num<50 }”><h1 style=”color:red”>20 &lt; num &lt; 50</h1></c:when>
<c:when test=”${param.num<10 }”><h1 style=”color:red”>num &lt; 10</h1></c:when>
<c:otherwise><h1 style=”color:red”>num &gt; 50</h1></c:otherwise>
</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:待循环的 集合
var:循环的时候 每次的变量
step:步进或是 间隔
begin:从哪一个下标元素开始
end:在哪一个下标元素结束

–>

<c:forEach items=”${list }” var=”l” step=”2″ begin=”0″ end=”10″ varStatus=”s”>
<span>${l }</span>|:|<span>${s.current }|${s.index }|${s.count }|${s.first }|${s.last}</span><br>
</c:forEach>
</body>

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,996
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,510
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,353
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,137
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848