Servlet代码 package cn.itcast.servlet; import java.io.IOException; import java.util.List; /** * 条件查询的servlet */ import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import cn.itcast.service.CustomerService; import cn.itcast.vo.Customer; public class ListConditionCustomerServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { /** * 1、接收数据 * 2、调用Service * 3、显示到JSP * */ //接收数据 request.setCharacterEncoding("UTF-8"); String paramName=request.getParameter("paramName"); String paramValue=request.getParameter("paramValue"); //调用Service CustomerService cs=new CustomerService(); List<Customer> list=cs.findByCondition(paramName,paramValue); //显示到JSP request.setAttribute("List", list); request.getRequestDispatcher("/myjsp/listCustomer.jsp").forward(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } } JSP <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!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>Insert title here</title> </head> <body> <h1>显示所有客户</h1> <form action="${pageContext.request.contextPath }/ListConditionCustomerServlet" method="post"> <table border="1" width="100%"> <tr> <td> <select name="paramName"> <!-- <% request.getParameter("paramName"); %> --> <option value="name"<c:if test="${paramName==""name"" }">selected</c:if>>按姓名 </option> <option value="type"<c:if test="${paramName==""type"" }">selected</c:if>>按类型 </option> </select> <input type="text" name="paramValue"/> <input type="submit" value="查询"> </td> </tr> </table> </form> <table border="1" width="100%"> <tr> <td>序号</td> <td>客户姓名</td> <td>客户性别</td> <td>客户生日</td> <td>客户电话</td> <td>客户邮箱</td> <td>客户爱好</td> <td>客户类型</td> <td>客户描述</td> <td>操作</td> </tr> <c:forEach var="customer" items="${list }" varStatus="status"> <tr> <td>${status.count }</td> <td>${customer.name }</td> <td>${customer.gender }</td> <td>${customer.birthday }</td> <td>${customer.cellphone }</td> <td>${customer.email }</td> <td>${customer.hobby }</td> <td>${customer.type }</td> <td>${customer.description }</td> <td><a href="${ pageContext.request.contextPath }/EditCustomerServlet?id=${ customer.id }">编辑</a>|<a href="${ pageContext.request.contextPath }/DeleteCustomerServlet?id=${ customer.id }">删除</a></td> </tr> </c:forEach> </table> </body> </html> |
|
5分 |
List里面有数据吗?
|
6分 |
1:你打个断点看看list有没有数据啊。
2:你的<c:forEach>语句中的item值。EL表达式写的不对啊。你在action中是List,怎么EL表达式成了list了。你把item的EL表达是改成${List }试试 |
5分 |
先看list里面有没有数据,然后在宅其他问题
|
10分 |
<c:forEach var=”customer” items=”${list }” varStatus=”status”> 这行中的list是不是该改成List
|
4分 |
debug 或者 打印
|
3分 |
5楼说的对;
要么debug一下,要么在合适的地方sysout一下; |
2分 |
感觉这里应该是这样的
CustomerService cs=new CustomerServiceImpl(); |
5分 |
首先你先确认你的list中有值,然后,你在的action里这么写的:
request.setAttribute(“List”, list); 所以你在前台取得时候应该是用List而不是list了 <c:forEach var=”customer” items=”${List }” varStatus=”status”> |