目录
1. 首先工程中要有JSTL的两个jar包: jstl.jar 和 standard.jar。
2. 其次在页面中引入标签库: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
在编写jsp页面时,很多时候需要对后台传来的参数进行判断,那么这时我们可以用jstl来操作。
1. 首先工程中要有JSTL的两个jar包: jstl.jar 和 standard.jar。
2. 其次在页面中引入标签库: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
1、if
(1)<c:if test="${条件}"></c:if>
例如:
<c:if test="${file_type==3}">
<th>是否导入数据库</th>
</c:if>
(2)还有一种方法就是使用java代码,注意jsp页面的java代码要写在<% %>之间,这样就可以时间java代码和jsp标签交互使用,实现一些功能
<%if(request.getParameter("moduleType")==null||request.getParameter("moduleType")==""){ %>
<%@include file="../../../inc/public.jsp"%>
<%@include file="../../../inc/formValidation.jsp"%>
<%@include file="../../../inc/uploader.jsp"%>
<%@include file="../../../inc/bootstrap-table.jsp"%>
<%}%>
2、if...else...
<c:choose>
<c:when test="${'<%=imgstr%>'==null}">
<img src="person/images/默认头像.png" id="img3"/>
</c:when>
<c:otherwise>
<img src="<%=imgstr%>" id="img4"/>
</c:otherwise></c:choose>
3、if...else if...else
<c:choose>
<c:when test="${条件}">
情况1...........
</c:when>
<c:when test="${条件}">
情况2...........
</c:when>
<c:otherwise>
否则。。。。。
</c:otherwise>
</c:choose>