一:定义一个类
package com.cloud.Demo1;
public class Cat {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
二:c_if标签
<%@ page language="java" import="java.util.*,com.cloud.Demo1.Cat" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP ‘c_if.jsp‘ starting page</title>
</head>
<body>
<%
request.setAttribute("a", "hello");
request.setAttribute("age", "10");
Cat cat1=new Cat();
cat1.setName("小白");
cat1.setAge(10);
request.setAttribute("cat", cat1);
%>
<!-- 判断a变量对应的值是不是hello -->
<h3>判断字符串</h3>
<c:if test="${a==‘hello‘ }">
ok!
</c:if>
<c:if test="">
bad!
</c:if>
<hr>
<h3>判断数值</h3>
<c:if test="${age==20 }">
等于20
</c:if>
<c:if test="${age<20 and age>5 }">
age<20 and age>5
</c:if>
<hr>
<h3>判断对象属性</h3>
<c:if test="${cat.age>3 }">
老鼠的年龄>3
</c:if>
</body>
</html>
三:c_choose标签
<%@ page language="java" import="java.util.*,com.cloud.Demo1.Cat" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP ‘c_choose.jsp‘ starting page</title>
</head>
<body>
<%
Cat cat1=new Cat();
cat1.setName("小白");
cat1.setAge(10);
request.setAttribute("cat", cat1);
%>
<h3>c_choose标签</h3>
<c:choose>
<c:when test="${cat.age<3 }">
<font color="red">老鼠很小</font>
</c:when>
<c:when test="${cat.age>3 and cat.age<8 }">
<font color="blue">老鼠年轻</font>
</c:when>
<c:otherwise>
<font color="yellow">老鼠老了</font>
</c:otherwise>
</c:choose>
</body>
</html>
版权声明:博主原创文章,转载请说明出处。http://blog.csdn.net/dzy21