jstl核心标签
代码
package cn.itcast.estore.web.servlet;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.itcast.estore.domain.Book;
import cn.itcast.estore.service.BookService;
import cn.itcast.estore.utils.BaseServlet;
public class BookServlet extends BaseServlet {
private static final long serialVersionUID = 1L;
public String findAll(HttpServletRequest req,HttpServletResponse resp){
BookService bookService = new BookService();
List<Book> list = bookService.findAll();
req.setAttribute("list", list);
return "/jsps/book/list.jsp";
}
页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>图书列表</title>
</head>
<body>
<c:forEach items="${list }" var="book">
<div class="icon">
<a href="${pageContext.request.contextPath }/bookServlet?method=findByBid&bid=${book.bid}">
<img src="${pageContext.request.contextPath }/${book.image}"
border="0" width="130" height="140"/></a>
<br/>
<a href="${pageContext.request.contextPath }/bookServlet?method=findByBid&bid=${book.bid}">${book.bname }</a>
</div>
</c:forEach>
</body>
</html>
struts标签
代码
package cn.itcast.crm.role.web
import java.util.List
import com.opensymphony.xwork2.ActionContext
import com.opensymphony.xwork2.ActionSupport
import cn.itcast.crm.dep.business.ebi.DepEbi
import cn.itcast.crm.dep.vo.DepModel
import cn.itcast.crm.role.business.ebi.RoleEbi
import cn.itcast.crm.role.vo.RoleModel
public class RoleAction extends ActionSupport{
public RoleModel rm = new RoleModel()
private RoleEbi roleEbi
public void setRoleEbi(RoleEbi roleEbi) {
this.roleEbi = roleEbi
}
//跳转到列表
public String list(){
List<RoleModel> roleList = roleEbi.getAll()
ActionContext.getContext().put("roleList", roleList)
return "list"
}
}
页面
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body >
<table width="100%" border="1" >
<tr class="henglan" style="font-weight:bold;">
<td width="6%" align="center">部门名称</td>
<td width="6%" align="center">职务名称</td>
<td width="7%" align="center">编辑</td>
</tr>
<s:iterator value="roleList" status="s">
<tr class="tabtd${ s.count%2+1 }">
<td align="center">${ dm.name }</td>
<td align="center">${ name }</td>
<td width="7%" align="center">
<s:a action="role_toUpdate">
<s:param name="rm.id" value="id"/>
<img src="images/button/modify.gif" class="img">
</s:a>
</td>
</tr>
</s:iterator>
</table>
</body>
</html>