用户信息管理系统演示视频(javaweb)
package com.veeja.cstm.dao;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import cn.itcast.jdbc.TxQueryRunner;
import com.veeja.cstm.domain.Customer;
import com.veeja.cstm.domain.PageBean;
/**
* 持久层
*
* @author Veeja.Liu
* @emial [email protected]
*
*/
public class CustomerDao {
private QueryRunner qr = new TxQueryRunner();
/**
* 添加用户
*
* @param c
*/
public void add(Customer c) {
try {
String sql = "insert t_customer values(?,?,?,?,?,?,?)";
Object[] params = { c.getCid(), c.getCname(), c.getGender(),
c.getBirthday(), c.getCellphone(), c.getEmail(),
c.getDescription() };
qr.update(sql, params);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
/**
*
* 查询所有
*
* @param ps
* @param pc
*
* @return
*/
public PageBean<Customer> findAll(int pc, int ps) {
try {
System.out.println("CustomerDao#findAll()启动!");
// 1. 创建pagebean对象
PageBean<Customer> pb = new PageBean<Customer>();
// 设置pagebean的pc和ps,
pb.setPc(pc);
pb.setPs(ps);
System.out.println("开始查询tr。");
// 得到tr,设置给pagebean,
String sql = "select count(*) from t_customer";
Number number = (Number) qr.query(sql, new ScalarHandler());
int tr = number.intValue();
pb.setTr(tr);
System.out.println("查询得到tr:" + tr);
// 得到beanlist,设置给pb
sql = "select * from t_customer order by cname limit ?,?";
List<Customer> beanList = qr.query(sql,
new BeanListHandler<Customer>(Customer.class), (pc - 1)
* ps, ps);
pb.setBeanList(beanList);
// 返回pagebean
System.out.println("dao马上返回一个pagebean。");
return pb;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
/**
* 根据id查询
*
* @param cid
* @return
*/
public Customer load(String cid) {
try {
String sql = "select * from t_customer where cid=?";
return qr
.query(sql, new BeanHandler<Customer>(Customer.class), cid);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
/**
* 修改客户信息
*
* @param customer
*/
public void edit(Customer c) {
try {
String sql = "update t_customer set cname=?,gender=?,birthday=?,cellphone=?,email=?,description=? where cid=?";
Object[] params = { c.getCname(), c.getGender(), c.getBirthday(),
c.getCellphone(), c.getEmail(), c.getDescription(),
c.getCid() };
qr.update(sql, params);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
/**
* 删除用户
*
* @param cid
*/
public void delete(String cid) {
try {
String sql = "delete from t_customer where cid=?";
qr.update(sql, cid);
} catch (SQLException e) {
e.printStackTrace();
}
}
// public PageBean query(Customer criteria, int pc, int ps) {
// try {
// System.out.println("现在执行dao的query方法。");
// // 给出sql模板
// // 给出一个SQL语句的前缀
// StringBuilder sql = new StringBuilder(
// "select * from t_customer where 1=1");
// // 为了添加不确定的参数,我们创建一个ArrayList,用来装载参数值
// List
// // 判断条件,完成想SQL语句中追加where子句
// // 给出参数
// String cname = criteria.getCname();
// if (cname != null && cname.trim() != "") {
// sql.append(" and cname LIKE ?");
// params.add("%" + cname + "%");
// }
//
// String gender = criteria.getGender();
// if (gender != null && gender.trim() != "") {
// sql.append(" and gender=?");
// params.add(gender);
// }
//
// String cellphone = criteria.getCellphone();
// if (cellphone != null && cellphone.trim() != "") {
// sql.append(" and cellphone LIKE ?");
// params.add("%" + cellphone + "%");
// }
//
// String email = criteria.getEmail();
// if (email != null && email.trim() != "") {
// sql.append(" and email like ?");
// params.add("%" + email + "%");
// }
//
// System.out.println("sql:" + sql.toString());
//
// // 调用query方法,使用结果集处理器beanlisthandler
// return (PageBean) qr.query(sql.toString(), new
// BeanListHandler(
// Customer.class), params.toArray());
// } catch (SQLException e) {
// // TODO Auto-generated catch block
// throw new RuntimeException(e);
// }
//
// }
public PageBean<Customer> query(Customer criteria, int pc, int ps) {
try {
System.out.println("dao的query方法!");
// 创建pagebean对象
// 设置已有属性,pc和ps
PageBean<Customer> pb = new PageBean<Customer>();
pb.setPc(pc);
pb.setPs(ps);
// 得到tr
StringBuilder cntsql = new StringBuilder(
"select count(*) from t_customer");
StringBuilder wheresql = new StringBuilder(" where 1=1");
// 为了添加不确定的参数,我们创建一个ArrayList,用来装载参数值
List<Object> params = new ArrayList<Object>();
// 判断条件,完成想SQL语句中追加where子句
// 给出参数
String cname = criteria.getCname();
if (cname != null && !cname.trim().isEmpty()) {
wheresql.append(" and cname LIKE ?");
params.add("%" + cname + "%");
}
String gender = criteria.getGender();
if (gender != null && !gender.trim().isEmpty()) {
System.out.println("DAO#query方法,得到的gender:"+gender);
wheresql.append(" and gender = ?");
params.add(gender);
}
String cellphone = criteria.getCellphone();
if (cellphone != null && !cellphone.trim().isEmpty()) {
wheresql.append(" and cellphone LIKE ?");
params.add("%" + cellphone + "%");
}
String email = criteria.getEmail();
if (email != null && !email.trim().isEmpty()) {
wheresql.append(" and email like ?");
params.add("%" + email + "%");
}
System.out
.println("sql:" + cntsql.toString() + wheresql.toString());
Number num = (Number) qr.query(
cntsql.toString() + wheresql.toString(),
new ScalarHandler(), params.toArray());
int tr = num.intValue();
pb.setTr(tr);
// 得到beanlist
StringBuilder sql = new StringBuilder("select * from t_customer");
// 查询beanlist这一步,还需要limit子句
StringBuilder limitsql = new StringBuilder(" limit ?,?");
// params中需要给出limit后面的两个值
params.add((pc - 1) * ps);
params.add(ps);
System.out.println("参数列表:" + params.toString());
// 执行
System.out.println("这是完整的查询SQL:" + sql.toString()
+ wheresql.toString() + limitsql.toString());
List<Customer> beanList = qr.query(
sql.append(wheresql).append(limitsql).toString(),
new BeanListHandler<Customer>(Customer.class),
params.toArray());
System.out.println("得到的beanlist:" + beanList);
pb.setBeanList(beanList);
System.out.println("得到的pb:" + pb);
return pb;
} catch (SQLException e) {
// TODO Auto-generated catch block
throw new RuntimeException(e);
}
}
}
package com.veeja.cstm.dao;
import org.junit.Test;
import cn.itcast.utils.CommonUtils;
import com.veeja.cstm.domain.Customer;
public class CustomerTest {
@Test
public void test() {
CustomerDao customerDao = new CustomerDao();
for (int i = 1; i <= 300; i++) {
Customer customer = new Customer();
customer.setCid(CommonUtils.uuid());
customer.setCname("cstm_"+i);
customer.setBirthday("2019-10-31");
customer.setGender(i%2==0?"男":"女");
customer.setEmail(customer.getCname()+"@veeja.com");
customer.setCellphone("10000"+i);
customer.setDescription("I am "+customer.getCname()+",my email is "+customer.getEmail()+".");
customerDao.add(customer);
}
}
}
package com.veeja.cstm.domain;
/**
* 领域对象
*
* @author Veeja.Liu
* @emial [email protected]
*
*/
public class Customer {
// cid CHAR(32) PRIMARY KEY,
// cname VARCHAR(40) NOT NULL,
// gender VARCHAR(6) NOT NULL,
// birthday CHAR(10),
// cellphone VARCHAR(15) NOT NULL,
// email VARCHAR(40),
// description VARCHAR(500)
private String cid;// 主键
private String cname;// 客户名称
private String gender;// 客户性别
private String birthday;// 客户生日
private String cellphone;// 客户电话
private String email;// 客户email
private String description;// 客户描述
public String getCid() {
return cid;
}
public void setCid(String cid) {
this.cid = cid;
}
public String getCname() {
return cname;
}
public void setCname(String cname) {
this.cname = cname;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getCellphone() {
return cellphone;
}
public void setCellphone(String cellphone) {
this.cellphone = cellphone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
return "Customer [cid=" + cid + ", cname=" + cname + ", gender="
+ gender + ", birthday=" + birthday + ", cellphone="
+ cellphone + ", email=" + email + ", description="
+ description + "]";
}
}
package com.veeja.cstm.domain;
import java.util.List;
public class PageBean<T> {
private int pc;// 当前页码page code
private int tp;// 总页数total page
private int tr;// 总记录数total record
private int ps;// 每页数量page size
private List<T> beanList;// 当前页码page size
private String url;//URL条件
public int getPc() {
return pc;
}
public void setPc(int pc) {
this.pc = pc;
}
/**
* 计算总页数
*
* @return
*/
public int getTp() {
// 通过总记录数和每页记录数来计算总页数
int tp = tr / ps;
return tr % ps == 0 ? tp : tp + 1;
}
public void setTp(int tp) {
this.tp = tp;
}
public int getTr() {
return tr;
}
public void setTr(int tr) {
this.tr = tr;
}
public int getPs() {
return ps;
}
public void setPs(int ps) {
this.ps = ps;
}
public List<T> getBeanList() {
return beanList;
}
public void setBeanList(List<T> beanList) {
this.beanList = beanList;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
package com.veeja.cstm.service;
import java.sql.SQLException;
import com.veeja.cstm.dao.CustomerDao;
import com.veeja.cstm.domain.Customer;
import com.veeja.cstm.domain.PageBean;
/**
* 业务层
*
* @author Veeja.Liu
* @emial [email protected]
*
*/
public class CustomerService {
private CustomerDao customerDao = new CustomerDao();
/**
* 添加客户
*
* @param c
*/
public void add(Customer c) {
customerDao.add(c);
}
/**
* 查找所有的用户,分页查询
*
* @param pc
* @param ps
* @return
*/
public PageBean<Customer> findAll(int pc, int ps) {
System.out.println("CustomerService#findAll()启动!");
return customerDao.findAll(pc, ps);
}
/**
* 加载用户信息
*
* @param cid
* @return
*/
public Customer load(String cid) {
return customerDao.load(cid);
}
/**
* 编辑用户信息
*
* @param customer
*/
public void edit(Customer customer) {
customerDao.edit(customer);
}
/**
* 删除用户信息
*
* @param cid
*/
public void delete(String cid) {
customerDao.delete(cid);
}
/**
* 查询用户信息,附带条件的查询
*
* @param criteria
* @param ps
* @param pc
* @return
* @throws SQLException
*/
public PageBean<Customer> query(Customer criteria, int pc, int ps)
throws SQLException {
System.out.println("调用service的query方法!!!!!!");
return customerDao.query(criteria, pc, ps);
}
}
package com.veeja.cstm.web.servlet;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.itcast.servlet.BaseServlet;
import cn.itcast.utils.CommonUtils;
import com.sun.swing.internal.plaf.basic.resources.basic;
import com.veeja.cstm.domain.Customer;
import com.veeja.cstm.domain.PageBean;
import com.veeja.cstm.service.CustomerService;
/**
* web层
*
* @author Veeja.Liu
* @emial [email protected]
*
*/
public class CustomerServlet extends BaseServlet {
private CustomerService customerService = new CustomerService();
/**
* 添加客户
*
* @return
*
* @return
*/
public String add(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 封装表单数据到Customer对象
// 补全:cid,使用uuid
// 使用service方法完成添加工作
// 向request域中保存成功信息
// 转发到msg.jsp
Customer c = (Customer) CommonUtils.toBean(request.getParameterMap(),
Customer.class);
c.setCid(CommonUtils.uuid());
customerService.add(c);
request.setAttribute("msg", "添加成功!");
return "f:/msg.jsp";
}
// /**
// * 查询所有用户
// *
// * @param request
// * @param response
// * @return
// * @throws ServletException
// * @throws IOException
// */
// public String findAll(HttpServletRequest request,
// HttpServletResponse response) throws ServletException, IOException {
// // 调用service,得到所有的客户
// // 保存到request域中
// // 转发到list.jsp
// request.setAttribute("cstmList", customerService.findAll());
// return "f:/list.jsp";
// }
public String findAll(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
System.out.println("CustomerServlet#findAll()启动!");
/**
* 1.获取页面传递的pc;2.给定ps的值;3.使用pc和ps调用service方法,得到pagebean,保存到request域中,
* 4.转发到list.jsp
*
*/
int pc = getPc(request);// 得到pc
int ps = 10;// 给定每页记录的数量,指定为10
PageBean<Customer> pb = customerService.findAll(pc, ps);// 传递ps,pc给service,得到pagebean
// 设置URL
pb.setUrl(getUrl(request));
request.setAttribute("pb", pb);// 保存到request域中
return "f:/list.jsp";// 转发到list.jsp
}
private int getPc(HttpServletRequest request) {
// 得到pc,如果pc不存在,说明pc=1,如果pc参数存在,需要转换成int类型即可
String value = request.getParameter("pc");
if (value == null || value.trim().isEmpty()) {
return 1;
}
return Integer.parseInt(value);
}
/**
* 编辑之前的加载工作
*
* @param request
* @param response
* @return
* @throws ServletException
* @throws IOException
*/
public String preEdit(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String cid = request.getParameter("cid");
Customer customer = customerService.load(cid);
request.setAttribute("cstm", customer);
return "f:/edit.jsp";
}
/**
* 编辑方法
*
* @param request
* @param response
* @return
* @throws ServletException
* @throws IOException
*/
public String edit(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Customer customer = CommonUtils.toBean(request.getParameterMap(),
Customer.class);
customerService.edit(customer);
request.setAttribute("msg", "修改成功!");
return "f:/msg.jsp";
}
/**
* 删除用户
*
* @param request
* @param response
* @return
* @throws ServletException
* @throws IOException
*/
public String delete(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
customerService.delete(request.getParameter("cid"));
request.setAttribute("msg", "删除成功!");
return "f:/msg.jsp";
}
// public String query(HttpServletRequest request, HttpServletResponse
// response)
// throws ServletException, IOException, SQLException {
//
// System.out.println("调用servlet!!!");
// // 封装到customer对象中,它只有四个属性,cname,gender,cellphone,email
// Customer criteria = CommonUtils.toBean(request.getParameterMap(),
// Customer.class);
// List cstmList = customerService.query(criteria);
// request.setAttribute("cstmList", cstmList);
// return "f:/list.jsp";
//
// }
public String query(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, SQLException {
System.out.println("servlet的query方法!");
System.out
.println("CustomerServlet#query()方法,输出URL:" + getUrl(request));
// 把条件封装到customer对象中
// 得到pc,给定ps
// 使用pc和ps调用service方法得到pagebean
// 把pagebean保存到request域中
// 转发到list.jsp
Customer criteria = CommonUtils.toBean(request.getParameterMap(),
Customer.class);
// 改成get请求方式后,需要处理编码问题
System.out.println("Servlet得到的gender(未处理编码):" + criteria.getGender());
criteria = encoding(criteria);
System.out.println("Servlet处理完编码的gender:" + criteria.getGender());
int pc = getPc(request);// 得到pc
int ps = 10;// 给定ps
PageBean<Customer> pb = customerService.query(criteria, pc, ps);
// 得到url,保存到pb中
pb.setUrl(getUrl(request));
request.setAttribute("pb", pb);
System.out.println("servlet操作完之后得到的pagebean:" + pb);
System.out.println("总页数:pb.tp:"+pb.getTp());
System.out.println("页码编号:pb.pc:"+pb.getPc());
return "f:/list.jsp";
}
/**
* 处理四样数据
*
* @param criteria
* @return
* @throws UnsupportedEncodingException
*/
private Customer encoding(Customer criteria)
throws UnsupportedEncodingException {
String cname = criteria.getCname();
String gender = criteria.getGender();
String cellphone = criteria.getCellphone();
String email = criteria.getEmail();
if (cname != null && !cname.trim().isEmpty()) {
cname = new String(cname.getBytes("ISO-8859-1"), "utf-8");
criteria.setCname(cname);
}
if (gender != null && !gender.trim().isEmpty()) {
gender = new String(gender.getBytes("ISO-8859-1"), "utf-8");
criteria.setGender(gender);
}
if (cellphone != null && !cellphone.trim().isEmpty()) {
cellphone = new String(cellphone.getBytes("ISO-8859-1"), "utf-8");
criteria.setCellphone(cellphone);
}
if (email != null && !email.trim().isEmpty()) {
email = new String(email.getBytes("ISO-8859-1"), "utf-8");
criteria.setEmail(email);
}
return criteria;
}
/**
* 截取URL:/项目名/servlet路径?参数字符串
*
* @param request
* @return
*/
private String getUrl(HttpServletRequest request) {
// 获取项目名
String contextPath = request.getContextPath();
// 获取servletPath,即/CustomerServlet
String servletPath = request.getServletPath();
// 获取问号之后的参数部分
String queryString = request.getQueryString();
// 判断参数部分中是否包含pc这个参数,如果包含,需要截取下去,不要这一部分。
if (queryString.contains("&pc=")) {
int index = queryString.lastIndexOf("&pc=");
queryString = queryString.substring(0, index);
}
return contextPath + servletPath + "?" + queryString;
}
}
<c3p0-config>
<default-config>
<property name="jdbcUrl">jdbc:mysql://localhost:3306/customersproperty>
<property name="driverClass">com.mysql.jdbc.Driverproperty>
<property name="user">rootproperty>
<property name="password">0000property>
<property name="acquireIncrement">3property>
<property name="initialPoolSize">10property>
<property name="minPoolSize">2property>
<property name="maxPoolSize">10property>
default-config>
<named-config name="oracle-config">
<property name="jdbcUrl">jdbc:mysql://localhost:3306/testproperty>
<property name="driverClass">com.mysql.jdbc.Driverproperty>
<property name="user">rootproperty>
<property name="password">0000property>
<property name="acquireIncrement">3property>
<property name="initialPoolSize">10property>
<property name="minPoolSize">2property>
<property name="maxPoolSize">10property>
named-config>
c3p0-config>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>添加客户title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css"
href="' /jquery/jquery.datepick.css'/>">
<script type="text/javascript"
src="' /jquery/jquery-1.5.1.js'/>">script>
<script type="text/javascript"
src="' /jquery/jquery.datepick.js'/>">script>
<script type="text/javascript"
src="' /jquery/jquery.datepick-zh-CN.js'/>">script>
<script type="text/javascript">
$(function() {
$("#birthday").datepick({
dateFormat : "yy-mm-dd"
});
});
function add() {
$(".error").text("");
var bool = true;
if (!$(":text[name=cname]").val()) {
$("#cnameError").text("客户名称不能为空");
bool = false;
}
if (!$("#male").attr("checked") && !$("#female").attr("checked")) {
$("#genderError").text("客户性别不能为空");
bool = false;
}
if (!$(":text[name=cellphone]").val()) {
$("#cellphoneError").text("手机不能为空");
bool = false;
}
if (!$(":text[name=email]").val()) {
$("#emailError").text("email不能为空");
bool = false;
}
if (bool) {
$("form").submit();
}
}
script>
<style type="text/css">
.error {
color: red;
}
style>
head>
<body>
<h3 align="center">添加客户h3>
<form action="' /CustomerServlet'/>" method="post">
<input type="hidden" name="method" value="add" />
<table border="0" align="center" width="40%"
style="margin-left: 100px;">
<tr>
<td width="100px">客户名称td>
<td width="40%"><input type="text" name="cname" />td>
<td align="left"><label id="cnameError" class="error"> label>
td>
tr>
<tr>
<td>客户性别td>
<td><input type="radio" name="gender" value="男" id="male" /> <label
for="male">男label> <input type="radio" name="gender" value="女"
id="female" /> <label for="female">女label>td>
<td><label id="genderError" class="error"> label>td>
tr>
<tr>
<td>客户生日td>
<td><input type="text" name="birthday" id="birthday"
readonly="readonly" />td>
<td><label id="birthdayError" class="error"> label>td>
tr>
<tr>
<td>手机td>
<td><input type="text" name="cellphone" />td>
<td><label id="cellphoneError" class="error"> label>td>
tr>
<tr>
<td>邮箱td>
<td><input type="text" name="email" />td>
<td><label id="emailError" class="error"> label>td>
tr>
<tr>
<td>描述td>
<td><textarea rows="5" cols="30" name="description">textarea>
td>
<td><label id="descriptionError" class="error"> label>td>
tr>
<tr>
<td> td>
<td><input type="button" value="添加客户" onclick="add()" /> <input
type="reset" value="重置" />td>
<td> td>
tr>
table>
form>
body>
html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>编辑客户title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="' /jquery/jquery.datepick.css'/>">
<script type="text/javascript" src="' /jquery/jquery-1.5.1.js'/>">script>
<script type="text/javascript" src="' /jquery/jquery.datepick.js'/>">script>
<script type="text/javascript" src="' /jquery/jquery.datepick-zh-CN.js'/>">script>
<script type="text/javascript">
$(function() {
$("#birthday").datepick({
dateFormat: "yy-mm-dd"
});
});
function add() {
$(".error").text("");
var bool = true;
if (!$(":text[name=cname]").val()) {
$("#cnameError").text("客户名称不能为空");
bool = false;
}
if (!$("#male").attr("checked") && !$("#female").attr("checked")) {
$("#genderError").text("客户性别不能为空");
bool = false;
}
if (!$(":text[name=cellphone]").val()) {
$("#cellphoneError").text("手机不能为空");
bool = false;
}
if (!$(":text[name=email]").val()) {
$("#emailError").text("email不能为空");
bool = false;
}
if (bool) {
$("form").submit();
}
}
script>
<style type="text/css">
.error {
color: red;
}
style>
head>
<body>
<h3 align="center">编辑客户h3>
<form action="' /CustomerServlet'/>" method="post">
<input type="hidden" name="method" value="edit">
<input type="hidden" name="cid" value="${cstm.cid }">
<table border="0" align="center" width="40%" style="margin-left: 100px;">
<tr>
<td width="100px">客户名称td>
<td width="40%"><input type="text" name="cname" value="${cstm.cname }" />
td>
<td align="left"><label id="cnameError" class="error"> label>
td>
tr>
<tr>
<td>客户性别td>
<td>
<input type="radio" name="gender" value="男" id="male" if test="${cstm.gender eq '男'}">checked='checked'c:if>/> <label for="male">男label>
<input type="radio" name="gender" value="女" id="female" if test="${cstm.gender eq '女'}">checked='checked'c:if>/> <label for="female">女label>
td>
<td><label id="genderError" class="error"> label>
td>
tr>
<tr>
<td>客户生日td>
<td><input type="text" name="birthday" id="birthday" readonly="readonly" value="${cstm.birthday}"/>
td>
<td><label id="birthdayError" class="error"> label>
td>
tr>
<tr>
<td>手机td>
<td><input type="text" name="cellphone" value="${cstm.cellphone}" />
td>
<td><label id="cellphoneError" class="error"> label>
td>
tr>
<tr>
<td>邮箱td>
<td><input type="text" name="email" value="${cstm.email}"/>
td>
<td><label id="emailError" class="error"> label>
td>
tr>
<tr>
<td>描述td>
<td><textarea rows="5" cols="30" name="description" >${cstm.description}textarea>
td>
<td><label id="descriptionError" class="error"> label>
td>
tr>
<tr>
<td> td>
<td><input type="button" value="编辑客户" onclick="add()" /> <input type="reset" value="重置" />
td>
<td> td>
tr>
table>
form>
body>
html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>主页title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
head>
<frameset rows="20%,*">
<frame src="' /top.jsp'/>" name="top"/>
<frame src="' /welcome.jsp'/>" name="main"/>
frameset>
html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<jsp:forward page="/frame.jsp" />
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>客户列表title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
head>
<body>
<h3 align="center">客户列表h3>
<table border="1" width="70%" align="center">
<tr>
<th>客户姓名th>
<th>性别th>
<th>生日th>
<th>手机th>
<th>邮箱th>
<th>描述th>
<th>操作th>
tr>
<c:forEach items="${pb.beanList}" var="cstm">
<tr>
<td>${cstm.cname}td>
<td>${cstm.gender }td>
<td>${cstm.birthday }td>
<td>${cstm.cellphone }td>
<td>${cstm.email }td>
<td>${cstm.description }td>
<td><a
href="' /CustomerServlet?method=preEdit&cid=${cstm.cid }'/>">编辑a>
<a
href="' /CustomerServlet?method=delete&cid=${cstm.cid }'/>">删除a>
td>
tr>
c:forEach>
table>
<br>
<center>
第${pb.pc }页.共${pb.tp }页 <a
href="${pb.url }&pc=1">首页a>
<c:if test="${pb.pc > 1}">
<a href="${pb.url }&pc=${pb.pc-1 }">上一页a>
c:if>
<%-- 计算begin和end --%>
<c:choose>
<%-- 如果总页数不足10页,就把所有的页都显示出来。 --%>
<c:when test="${pb.tp <= 10 }">
<c:set var="begin" value="1" />
<c:set var="end" value="${pb.tp }" />
c:when>
<c:otherwise>
<%-- 当总页数大于10时,通过公式计算出begin和end --%>
<c:set var="begin" value="${pb.pc-5 }" />
<c:set var="end" value="${pb.pc+4 }" />
<%-- 头溢出 --%>
<c:if test="${begin < 1 }">
<c:set var="begin" value="1" />
<c:set var="end" value="10" />
c:if>
<%-- 尾溢出 --%>
<c:if test="${end > pb.tp }">
<c:set var="begin" value="${pb.tp - 9 }" />
<c:set var="end" value="${pb.tp }" />
c:if>
c:otherwise>
c:choose>
<%-- 循环遍历页码列表 --%>
<c:forEach var="i" begin="${begin }" end="${end }" >
<c:choose>
<c:when test="${i eq pb.pc }">
[${i }]
c:when>
<c:otherwise>
<a href="${pb.url }&pc=${i}">
[${i }]
a>
c:otherwise>
c:choose>
c:forEach>
<c:if test="${pb.pc < pb.tp}">
<a
href="${pb.url }&pc=${pb.pc+1 }">下一页a>
c:if>
<a
href="${pb.url }&pc=${pb.tp }">尾页a>
center>
body>
html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>My JSP 'msg.jsp' starting pagetitle>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
head>
<body>
<h1 style="color:green;" align="center">恭喜,${msg }h1>
body>
html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>高级搜索title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
head>
<body>
<h3 align="center">高级搜索h3>
<form action="' /CustomerServlet'/>" method="get">
<input type="hidden" name="method" value="query">
<table border="0" align="center" width="40%"
style="margin-left: 100px;">
<tr>
<td width="100px">客户名称td>
<td width="40%"><input type="text" name="cname" />td>
tr>
<tr>
<td>客户性别td>
<td><select name="gender">
<option value="">==请选择性别==option>
<option value="男">男option>
<option value="女">女option>
select>td>
tr>
<tr>
<td>手机td>
<td><input type="text" name="cellphone" />td>
<td><label id="cellphoneError" class="error"> label>td>
tr>
<tr>
<td>邮箱td>
<td><input type="text" name="email" />td>
<td><label id="emailError" class="error"> label>td>
tr>
<tr>
<td> td>
<td><input type="submit" value="搜索" /> <input type="reset"
value="重置" />td>
<td> td>
tr>
table>
form>
body>
html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<base target="main">
<title>My JSP 'top.jsp' starting pagetitle>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
head>
<body style="text-align: center;">
<h1>客户关系管理系统h1>
<a href="' /add.jsp'/>">添加客户a> |
<a href="' /CustomerServlet?method=findAll'/>">查询客户a> |
<a href="' /query.jsp'/>">高级搜索a>
body>
html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>My JSP 'welcome.jsp' starting pagetitle>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
head>
<body>
<h1 align="center">欢迎登录本系统h1>
body>
html>
END.