JSTL(JSP标准标签库)常用标签用法 (流程控制:if,choose,when,otherwise; 迭代:forEach)

本文并未把所有的JSTL标签罗列出来,只是写下了几个相对使用量较大的标签

1、流程控制:if,choose,when,otherwise

xx

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

   
       
                
       
       
                
       
       
                
       
       
           

No choice

      
  
red
yellow
blue
  
2、迭代:forEach

 遍历集合


    ${i} ${index}  

遍历Map


  key=${m.key},value=${m.value}


打印1到10


  ${i}
 

<%@page import="tarena.jstl.Student,java.util.*"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
  Collection students = new ArrayList();
  students.add(new Student("001","zhangsan",23));
  students.add(new Student("002","lisi",22));
  students.add(new Student("003","wangwu",21)); 
  request.setAttribute("stus", students);
%>

  
    ${stu.id}
        ${stu.name}
        ${stu.age}
    
  

<% Map stus = new HashMap(); stus.put("001", new Student("001","zhangsan",23)); stus.put("002", new Student("002","lisi",22)); stus.put("003", new Student("003","wangwu",21));    request.setAttribute("stumap", stus); %> ${stu.value.id} ${stu.value.name} ${stu.value.age}

${status.count} ${status.current.name} ${status.current.age}

No.${i} ${stus[i].id} ${stus[i].name} ${stus[i].age}



你可能感兴趣的:(JSTL)