标签:判断 忽略 开始 不显示 case ret color body jar包
<%@ page import="java.util.List" %> <%@ page import="java.util.ArrayList" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> ${3 > 4} \${3 > 4} <hr> <h3>算数运算符</h3> ${3 + 4}<br> ${3 / 4}<br> ${3 div 4}<br> ${3 % 4}<br> ${3 mod 4}<br> <h3>比较运算符</h3> ${3 == 4}<br> <h3>逻辑运算符</h3> ${3 > 4 && 3 < 4}<br> ${3 > 4 and 3 < 4}<br> <h4>empty运算符</h4> <% String str = ""; request.setAttribute("str",str); List list = new ArrayList(); request.setAttribute("list",list); %> ${not empty str} ${not empty list} </body> </html>
<%@ page import="java.util.List" %> <%@ page import="java.util.ArrayList" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>el获取域中的数据</title> </head> <body> <% //在域中存储数据 session.setAttribute("name","李四"); request.setAttribute("name","张三"); session.setAttribute("age","23"); request.setAttribute("str",""); %> <h3>el获取值</h3> ${requestScope.name} ${sessionScope.age} ${sessionScope.haha} ${name}//张三 ${sessionScope.name} </body> </html>
<%@ page import="cn.itcast.domain.User" %> <%@ page import="java.util.*" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>el获取数据</title> </head> <body> <% User user = new User(); user.setName("张三"); user.setAge(23); user.setBirthday(new Date()); request.setAttribute("u",user); List list = new ArrayList(); list.add("aaa"); list.add("bbb"); list.add(user); request.setAttribute("list",list); Map map = new HashMap(); map.put("sname","李四"); map.put("gender","男"); map.put("user",user); request.setAttribute("map",map); %> <h3>el获取对象中的值</h3> ${requestScope.u}<br> <%-- * 通过的是对象的属性来获取 * setter或getter方法,去掉set或get,在将剩余部分,首字母变为小写。 * setName --> Name --> name --%> ${requestScope.u.name}<br> ${u.age}<br> ${u.birthday}<br> ${u.birthday.month}<br> ${u.birStr}<br> <h3>el获取List值</h3> ${list}<br> ${list[0]}<br> ${list[1]}<br> ${list[10]}<br> ${list[2].name} <h3>el获取Map值</h3> ${map.gender}<br> ${map["gender"]}<br> ${map.user.name} </body> </html>
package cn.itcast.domain;
import java.text.SimpleDateFormat;
import java.util.Date;
public class User {
private String name;
private int age;
private Date birthday;
public User(String name, int age, Date birthday) {
this.name = name;
this.age = age;
this.birthday = birthday;
}
public User() {
}
/**
* 逻辑视图
* @return
*/
public String getBirStr(){
if(birthday != null){
//1.格式化日期对象
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//2.返回字符串即可
return sdf.format(birthday);
}else{
return "";
}
}
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;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>el隐式对象</title> </head> <body> ${pageContext.request}<br> <h4>在jsp页面动态获取虚拟目录</h4> ${pageContext.request.contextPath} <% %> </body> </html>
<%@ page import="java.util.List" %> <%@ page import="java.util.ArrayList" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>if标签</title> </head> <body> <%-- c:if标签 1. 属性: * test 必须属性,接受boolean表达式 * 如果表达式为true,则显示if标签体内容,如果为false,则不显示标签体内容 * 一般情况下,test属性值会结合el表达式一起使用 2. 注意:c:if标签没有else情况,想要else情况,则可以在定义一个c:if标签 --%> <c:if test="true"> <h1>我是真...</h1> </c:if> <br> <% //判断request域中的一个list集合是否为空,如果不为null则显示遍历集合 List list = new ArrayList(); list.add("aaaa"); request.setAttribute("list",list); request.setAttribute("number",4); %> <c:if test="${not empty list}"> 遍历集合... </c:if> <br> <c:if test="${number % 2 != 0}"> ${number}为奇数 </c:if> <c:if test="${number % 2 == 0}"> ${number}为偶数 </c:if> </body> </html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>choose标签</title> </head> <body> <%-- 完成数字编号对应星期几案例 1.域中存储一数字 2.使用choose标签取出数字 相当于switch声明 3.使用when标签做数字判断 相当于case 4.otherwise标签做其他情况的声明 相当于default --%> <% request.setAttribute("number",51); %> <c:choose> <c:when test="${number == 1}">星期一</c:when> <c:when test="${number == 2}">星期二</c:when> <c:when test="${number == 3}">星期三</c:when> <c:when test="${number == 4}">星期四</c:when> <c:when test="${number == 5}">星期五</c:when> <c:when test="${number == 6}">星期六</c:when> <c:when test="${number == 7}">星期天</c:when> <c:otherwise>数字输入有误</c:otherwise> </c:choose> </body> </html>
<%@ page import="java.util.ArrayList" %> <%@ page import="java.util.List" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>foreach标签</title> </head> <body> <%-- foreach:相当于java代码的for语句 1. 完成重复的操作 for(int i = 0; i < 10; i ++){ } * 属性: begin:开始值 end:结束值 var:临时变量 step:步长 varStatus:循环状态对象 index:容器中元素的索引,从0开始 count:循环次数,从1开始 2. 遍历容器 List<User> list; for(User user : list){ } * 属性: items:容器对象 var:容器中元素的临时变量 varStatus:循环状态对象 index:容器中元素的索引,从0开始 count:循环次数,从1开始 --%> <c:forEach begin="1" end="10" var="i" step="2" varStatus="s"> ${i} <h3>${s.index}<h3> <h4> ${s.count} </h4><br> </c:forEach> <hr> <% List list = new ArrayList(); list.add("aaa"); list.add("bbb"); list.add("ccc"); request.setAttribute("list",list); %> <c:forEach items="${list}" var="str" varStatus="s"> ${s.index} ${s.count} ${str}<br> </c:forEach> </body> </html>
EL JSTL和简单MVC 还有三层架构(这次我先鸽了)的学习
标签:判断 忽略 开始 不显示 case ret color body jar包
原文地址:https://www.cnblogs.com/YanZhuDL/p/11627986.html