java依赖包
界面导入c标签
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
基本语法
1. java存变量
@Controller
@RequestMapping("study")
public class StudyController {
@RequestMapping("init.action")
public String init(HttpSession session){
List<GyStudent> students=new ArrayList<GyStudent>();
for(int i=0;i<7;i++){
Object student=new Object ();
}
session.setAttribute("students", students);
return "study/checkTask";
}
}
2. jsp取变量
${students}
3. jsp遍历集合
<c:forEach var="stu" items="${students}">
<div style="display: flex; width: 33%">
<div>
<img src="/guoya-client/img/company/guoya_logo.jpg" height="40px">
</div>
</div>
</c:forEach>
4. jsp条件判断
<c:if test="${stu.sno % 3 == 2 && stu.sno>0}">
</div>
<div style="display: flex;">
</c:if>
4. 下拉框和选项
<c:set var="schoolid" value="${pageData.SchoolId}" scope="request"/>
<select name="schoolId" id="schoolId" style="width: 95%">
<option value="0">==请选择==</option>
<c:forEach items="${organizeList}" var="var" varStatus="vs">
<option value="${var.name_code}" <c:if test="${var.name_code==schoolid}">selected</c:if> > ${var.name}</option>
</c:forEach>
</select>
5. 格式化时间对象
第一步,引入工具包:
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
第二步,调用格式化标签:
1、显示星期几:
<fmt:formatDate value="${date }" pattern="E"/>
2、显示年月日:
<fmt:formatDate value="${date }" pattern="yyyy-MM-dd"/>
3、显示时分秒:
<fmt:formatDate value="${date }" pattern="HH:mm:ss"/>
遍历HashMap
<c:forEach items="${map}" var="entry">
<h1 class="caption">${entry.key}</h1>//迭代得到键所有的
<c:if test="${empty entry.value}">
包含其它jsp或者html文件
静态包含:<%@include file="被包含页面"%>和动态包含:<jsp:include page="被包含页面"flush="true">
判断集合是否为空
<c:if test="${empty list}">
<c:if test="${list== null || fn:length(list) == 0}">