如何在jsp页面上做if判断

目录

1. 首先工程中要有JSTL的两个jar包:   jstl.jar 和 standard.jar。

2. 其次在页面中引入标签库:    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

1、if

2、if...else...

3、if...else if...else


在编写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>

 

  • 9
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值