清风明月的博客

你好


  • 首页

  • 归档

  • 标签

  • 分类

  • 关于

jstl

发表于 2015-10-07 | 分类于 JAVA

为了在JSP页面中使用JSTL标签,那么需要在JSP页面中引入 JSTL 声明和启用EL的声明,如下所示:

1
2
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

###c:out
out.jsp:

1
action parameters is : <c:out value="${param.action}"></c:out>

访问:
localhost:8080/out.jsp?action=add
结果:
action parameters is : add

###c:if
if.jsp:

1
2
3
4
5
6
7
8
9
10
11
12
<c:if test="${param.action=='add'}">
<table>
<tr>
<td>账号</td>
<td><input type="text" name="login"/></td>
</tr>
<tr>
<td>真实姓名</td>
<td><input type="text" name="name"/></td>
</tr>
</table>
</c:if>

访问:
localhost:8080/out.jsp?action=add

但是 if 标签没有 else 的功能,如果要实现类似于 java 中 if...else 的功能,需要使用 choose 标签。

choose.jsp:

1
2
3
4
5
6
7
8
<c:choose>
<c:when test="${param.action}" >
when 标签的输出
</c:when>
<c:otherwise>
otherwise 标签的输出
</c:otherwise>
</c:choose>

1…282930…34

清风明月多多想毕业

用宽容的胸怀接受不能改变的,用极大的勇气改变能够改变的

34 日志
3 分类
7 标签
© 2018 清风明月多多想毕业
由 Hexo 强力驱动
|
主题 — NexT.Mist v5.1.3