每日记录
今天学习了jsp的一些东西
c:forEach:相当于for循环
<%-- varstatus:定义序号,index从0开始,count从一开始 --%> <c:forEach items="${brand}" var="brands" varStatus="status"> <tr align="center"> <%--<td>${brands.id}</td>--%> <td>${status.count}</td> <td>${brands.brandName}</td> <td>${brands.companyName}</td> <td>${brands.ordered}</td> <td>${brands.description}</td> <c:if test="${brands.status==1}"><td>启用</td></c:if> <c:if test="${brands.status!=1}"><td>禁用</td></c:if> <%--<td>${brands.status}</td>--%> <td><a href="#">修改</a> <a href="#">删除</a></td> </tr> </c:forEach>
c:if标签
用来完成逻辑判断,替换java if else
<%-- c:if: 用来完成逻辑判断,替换java if else --%> <%--<c:if test="true"> <h1>true</h1> </c:if> <c:if test="flase"> <h1>flase</h1> </c:if>--%> <c:if test="${status==1}">启用</c:if> <c:if test="${status==0}">禁用</c:if>
${}的使用
<%@ page isELIgnored="false" %>这个语句有的需要写,有的不需要,如果网页输出只有${}这个,则需要写
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %> <html> <head> <title>Title</title> </head> <body> ${brand} </body> </html>
//1.准备数据
List<Brand> brands = new ArrayList<Brand>();
brands.add(new Brand(1,"三只松鼠","三只松鼠",100,"三只松鼠,好吃不上火",1));
brands.add(new Brand(2,"优衣库","优衣库",200,"优衣库,服适人生",0));
brands.add(new Brand(3,"小米","小米科技有限公司",1000,"为发烧而生",1));
//2.存储到requst域中
request.setAttribute("brand",brands);
request.setAttribute("status",1);
//3.转发到el-demo.jsp
/* request.getRequestDispatcher("el-demo.jsp").forward(request,response);*/
/* request.getRequestDispatcher("/jstl-if.jsp").forward(request,response);*/
<%%>标签
比较落后,这个是用来在jsp中写Java的可以在Java语句和jsp中跳跃使用
<% for (int i=0;i<brands.size();i++){ Brand brand=brands.get(i); %> <tr align="center"> <td><%=brand.getId()%></td> <td><%=brand.getBrandName()%></td> <td><%=brand.getCompanyName()%></td> <td><%=brand.getOrdered()%></td> <td><%=brand.getDescription()%></td> <% if (brand.getStatus()==1){ %> } <td><%="启用" %></td> <% }else { %> <td><%="禁用"%></td> <% } %> <td><a href="#">修改</a> <a href="#">删除</a></td> </tr> <% } %>