先将数据库的数据获取,用session将数据存起来。
HttpSession session = request.getSession();
session.setAttribute("userDetail", userDetailDao.userDetail());
[plain] view plain copy
public class UserDetailAction extends HttpServlet {
private static final long serialVersionUID = 1L;
public UserDetailAction() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
UserDetailDao userDetailDao = new UserDetailDao();
HttpSession session = request.getSession();
session.setAttribute("userDetail", userDetailDao.userDetail());
response.sendRedirect("managerForUserDetail.jsp");
}
用jstl先导入两个jar包(standard.jar和jstl.jar),放在lib文件夹下并add build path
在web.xml配置(来自菜鸟)
[html] view plain copy
在jsp中引用核心标签库的语法引用核心标签库的语法
注释部分是没有使用jstl时,在jsp页面添加Java代码,
使用jstl的c:forEach是迭代一个集合中的对象,var表示变量名,items是将被循环的集合。
[html] view plain copy
<%@ page language="java" contentType="text/html; charset=GBK"
import="java.util.*,com.qingzheng.entity.User,com.qingzheng.servlet.UserDetailAction,
com.qingzheng.dao.UserDetailDao"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
UserAccount | User name | Password | Sex | Telephone Number | Operation |
---|
|