写了一个客户关系管理系统,进行查询的时候值没取到是什么原因
Servlet代码
程序代码:package cn.itcast.servlet;
import 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. prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. 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>







