12-JSTL简介

来源:互联网 发布:网络运维书籍推荐 编辑:程序博客网 时间:2024/04/30 04:39

【注意】

value="${person.id}"  $后面是一对大括号{ } ,不是小括号( )


【源代码】

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><%@page import="java.util.List"%><%@page import="com.rupeng.web2.Person"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>人员列表</title></head><body><p><a href="person?action=addnew">新增</a></p><table><thead><tr><td>Id</td><td>姓名</td><td>年龄</td><td>编辑</td><td>删除</td></tr></thead><tbody><%List<Person> persons = (List<Person>)request.getAttribute("persons");for(Person person : persons){%><tr><td><%=person.getId() %></td><td><%=person.getName() %></td><td><%=person.getAge() %></td><td><a href="person?action=edit&id=<%=person.getId() %>">编辑</a></td><td><a href="person?action=delete&id=<%=person.getId() %>">删除</a></td></tr><%} %></tbody></table></body></html>



【JSTL】


<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><%@page import="java.util.List"%><%@page import="com.rupeng.web2.Person"%><%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>人员列表</title></head><body><p><a href="person?action=addnew">新增</a></p><table><thead><tr><td>Id</td><td>姓名</td><td>年龄</td><td>编辑</td><td>删除</td></tr></thead><tbody><c:forEach items="${persons}" var="person"><tr><td><c:out value="${person.id}"/></td><td><c:out value="${person.name}"/></td><td><c:out value="${person.age}"/></td><td><a href="person?action=edit&id=<c:out value='${person.id}'/>">编辑</a></td><td><a href="person?action=delete&id=<c:out value='${person.id}'/>">删除</a></td></tr></c:forEach></tbody></table></body></html>


越大项目越能发现其好处

下一章节详细学习

0 0