日期:2014-05-17 浏览次数:20841 次
package com.zemo.hibernatespring.action;
import java.io.IOException;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import com.zemo.hibernatespring.bean.User;
import com.zemo.hibernatespring.biz.impl.UserBizImpl;
@Controller
public class UserListServlet extends HttpServlet {
@Resource
private UserBizImpl userBiz;
private static final long serialVersionUID = -8609429659212933530L;
@Override
public void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
System.out.println("-----------service--------------");
List<User> users = userBiz.getAllUser();
request.setAttribute("users", users);
System.out.println("---------------" + users.size() + "-----------");
getServletConfig().getServletContext()
.getRequestDispatcher("/userList.jsp")
.forward(request, response);
}
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="com.zemo.hibernatespring.bean.User"%>
<%@ page import="java.util.*" %>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc//DTD JSP Tag Library 1//EN"
"http://javasuncom/j2ee/dtds/web-jsptaglibrary_1_dtd">
<html>
<head>
<title>用户列表</title>
</head>
<body>
<table border="1" cellpadding="0" cellspacing="0" align="center" width="800">
<tr>
<th>ID</th>
<th>用户名</th>
<th>密码</th>
</tr>
<%
List<User> users = (List<User>)request.getAttribute("users");
if (users == null || users.size() == 0) {
%>
<tr>
<td colspan="3">没有符合条件的数据232</td>