当前位置: 移动技术网 > IT编程>开发语言>Java > JSP中使用JSTL按不同条件输出内容的方法

JSP中使用JSTL按不同条件输出内容的方法

2017年12月08日  | 移动技术网IT编程  | 我要评论

本文实例讲述了jsp中使用jstl按不同条件输出内容的方法。分享给大家供大家参考。具体如下:

conditionalcontentjstl.jsp页面:

<%@ page language="java" contenttype="text/html;charset=utf-8" %>
<%@ taglib uri="/web-inf/tld/c-rt.tld" prefix="c-rt" %>
<html>
<head>
 <title>java code geeks snippets - conditional content with jstl in jsp page</title>
</head>
<body>
 <%-- if condition --%>
 <c-rt:if test='${param.myparam1 == "myvalue1"}'>
  this is printed if parameter "myparam1" equals "myvalue1" </br>
 </c-rt:if>
 <%-- if/else condition --%>
 <c-rt:choose>
  <c-rt:when test='${param.myparam2 == "myvalue2"}'>
   this is printed if parameter "myparam2" equals "myvalue2" </br>
  </c-rt:when>
  <c-rt:otherwise>
   this is printed if parameter "myparam2" does not equal "myvalue2" </br>
  </c-rt:otherwise>
 </c-rt:choose>
 <%-- multiple conditions --%>
 <c-rt:choose>
  <c-rt:when test='${param.myparam3 == "0"}'>
   this is printed if parameter "myparam1" equals 0 </br>
  </c-rt:when>
  <c-rt:when test='${param.myparam3 == "1"}'>
   this is printed if parameter "myparam1" equals 1 </br>
  </c-rt:when>
  <c-rt:otherwise>
   this is printed for any other value of the parameter </br>
  </c-rt:otherwise>
 </c-rt:choose>
</body>

希望本文所述对大家的jsp程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网