////////////////////////////////////////////// // 数组 String[] str = {"aaa","bbb","ccc"}; getServletContext().setAttribute("str", str); <c:forEach items="${str }" var="srtArr"> ${srtArr } </c:forEach> // 集合 ArrayList<String> list = new ArrayList<>(); list.add("zhangsan"); list.add("lisi"); list.add("wangwu"); <c:forEach items="${list }" var="strList"> ${strList } </c:forEach> // 集合 ArrayList<Person> PList = new ArrayList<>(); PList.add(new Person("p1","pzs","11")); PList.add(new Person("p2","pls","12")); PList.add(new Person("p3","pww","13")); request.getSession().setAttribute("PList", PList); <c:forEach items="${PList }" var="per"> ${per.getPid() } ${per.getPname() } ${per.getPage() } </c:forEach> // map集合 HashMap<Integer, String> hm = new HashMap<>(); hm.put(1, "11111"); hm.put(2, "22222"); hm.put(3, "33333"); request.getSession().setAttribute("hm", hm); <c:forEach items="${hm }" var="entry"> ${entry.key } ${entry.value } </c:forEach> // map集合值是一个对象 HashMap<String, Person> map = new HashMap<>(); map.put("p001", new Person("p001","zs","15")); map.put("p002", new Person("p002","ls","23")); map.put("p003", new Person("p003","ww","19")); request.getSession().setAttribute("map", map); <c:forEach items="${map }" var="entry" > ${entry.key } 这个是键<br/> ${entry.value.getPid() }<br/> ${entry.value.getPname() }<br/> ${entry.value.getPage() }<br/> </c:forEach> //////////////////////////////////////////////////// <c:url>标签 <c:url>标签 <c:url value="/login.jsp"/>这个标签这样执行的结果是 项目名/login.jsp 使用: <form action="<c:url value='/product?method=2'/>" method="post"> <a href="<c:url value="/product?method=5&pid=${pro.pid }"/>">商品详情</a> ///////////////////////////////////////////////////// <!-- 判断数据库中没有任何商品 --> <c:if test="${empty pb.datas }"> <tr> <th colspan="9" style="color: red; text-align: center;">查无商品</th> </tr> </c:if>
EL表达式的使用
猜你喜欢
转载自blog.csdn.net/wildwolf_001/article/details/79727069
今日推荐
周排行