客户管理系统的增删改查
2016-12-28 19:41
225 查看
bean:
package com.heima.bean;
import java.io.Serializable;
import java.util.Date;
//create table customer(
// id varchar(100) primary key,
// name varchar(100),
// gender varchar(4),# 1 male 0 female
// birthday date,
// cellphone varchar(20),
// email varchar(40),
// hobby varchar(100),#eat,sleep
// type varchar(40),#vip|normal
// description varchar(255)
// );
public class Customer implements Serializable{
private String id ;
private String name ;
private String gender ;
private Date birthday ;
private String cellphone ;
private String email ;
private String hobby ;
private String type ;
private String description ;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date 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 getHobby() {
return hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
formbean:
package com.heima.web.formbean;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
public class CustomerFormBean implements Serializable{
private String id ;
private String name ;
private String gender ;
private String birthday ;
private String cellphone ;
private String email ;
private String[] hobby ;
private String type ;
private String description ;
private Map<String,String> errors = new HashMap<String,String>() ;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
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[] getHobby() {
return hobby;
}
public void setHobby(String[] hobby) {
this.hobby = hobby;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean validate(){
//省略
return true ;
}
}
dao:
package com.heima.dao;
import java.util.List;
import com.heima.bean.Customer;
public interface CustomerDao {
/**
* 添加一个客户
* @param customer 要添加的客户
* @return 天成成功返回TRUE,否则返回FALSE
*/
public boolean add(Customer customer) ;
/**
* 修改一个客户
* @param customer 要修改的客户
* @return 成功返回TRUE,否则返回FALSE
*/
public boolean update(Customer customer) ;
/**
* 根据客户的主键删除客户
* @param id 要删除客户的编号
* @return 删除成功返回TRUE,否则返回FALSE
*/
public boolean delete(String id) ;
/**
* 获取所有的客户
* @return 返回所有客户的集合
*/
public List<Customer> getAllCustomer() ;
/**
* 根据客户的编号查询客户
* @param id 客户的编号
* @return 查出来返回此客户,否则返回null
*/
public Customer findCustomerById(String id) ;
}
utils:
JdbcUtils:
package com.heima.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;
//专门用于数据库的工具类
public class JdbcUtils {
private static String driverClass = "" ;
private static String url = "" ;
private static String user = "" ;
private static String password = "";
static{
ResourceBundle rb = ResourceBundle.getBundle("dbcfg") ;
driverClass = rb.getString("driverClass") ;
url = rb.getString("url") ;
user = rb.getString("user") ;
password = rb.getString("password") ;
try {
Class.forName(driverClass) ;
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConnection(){
try {
return DriverManager.getConnection(url, user, password) ;
} catch (SQLException e) {
e.printStackTrace();
}
return null ;
}
public static void release(ResultSet rs ,Statement stmt,Connection conn){
if(rs != null){
try {
rs.close() ;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(stmt != null){
try {
stmt.close() ;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn != null){
try {
conn.close() ;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
WebUtils:
package com.heima.utils;
import java.lang.reflect.InvocationTargetException;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.beanutils.BeanUtils;
//专门为页面服务: 封装了页面的信息
public class WebUtils {
public static <T> T fillFormBean(Class<T> clazz,HttpServletRequest request){
T t = null ;
try {
t = clazz.newInstance() ;
BeanUtils.populate(t, request.getParameterMap()) ;
} catch (Exception e) {
e.printStackTrace();
}
return t ;
}
}
WebTools:
package com.heima.utils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;
import sun.misc.BASE64Encoder;
//用来做一些常用的一些操作
public class WebTools {
//获取一个新的唯一的id
public static String createNewId(){
String id = UUID.randomUUID().toString() ;
MessageDigest md;
try {
md = MessageDigest.getInstance("md5");
byte[] bs = md.digest(id.getBytes()) ;
BASE64Encoder base = new BASE64Encoder() ;
id = base.encode(bs) ;
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return id ;
}
}
dao.impl:
service:
package com.heima.service;
import java.util.List;
import com.heima.bean.Customer;
public interface CustomerService {
/**
* 添加一个客户
* @param customer 要天剑的客户
* @return 天成成功返回TRUE,否则返回FALSE
*/
public boolean add(Customer customer) ;
/**
* 修改一个客户
* @param customer 要修改的客户
* @return 成功返回TRUE,否则返回FALSE
*/
public boolean update(Customer customer) ;
/**
* 根据客户的主键删除客户
* @param id 要删除客户的编号
* @return 删除成功返回TRUE,否则返回FALSE
*/
public boolean delete(String id) ;
/**
* 获取所有的客户
* @return 返回所有客户的集合
*/
public List<Customer> getAllCustomer() ;
/**
* 根据客户的编号查询客户
* @param id 客户的编号
* @return 查出来返回此客户,否则返回null
*/
public Customer findCustomerById(String id) ;
}
service.iimpl:
Controller:
package com.heima.web.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.locale.converters.DateLocaleConverter;
import com.heima.bean.Customer;
import com.heima.service.CustomerService;
import com.heima.service.impl.CustomerServiceImpl;
import com.heima.utils.WebTools;
import com.heima.utils.WebUtils;
import com.heima.web.formbean.CustomerFormBean;
//控制请求的转向(流程控制)(前端控制器)
public class Controller extends HttpServlet {
CustomerService cs = new CustomerServiceImpl();
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
// 拿到页面传递的数据
String op = request.getParameter("op");
if ("all".equals(op)) {
listAll(request, response);
} else if ("add".equals(op)) {
addCustomer(request, response);
} else if ("toupdate".equals(op)) {
toUpdate(request, response);
} else if ("update".equals(op)) {
update(request, response);
} else if("delete".equals(op)){
delete(request,response) ;
} else if("delmore".equals(op)){
delMore(request,response) ;
}
}
//删除多条数据
private void delMore(HttpServletRequest request,
HttpServletResponse response)throws ServletException, IOException {
//拿到页面的数据
String ids = request.getParameter("ids") ;
//由于ids后面多了一个逗号,记得去掉
ids = ids.substring(0, ids.length()-1) ;
//拆分字符串
String [] strIds = ids.split(",") ;
System.out.println(strIds[0]);
//循环删除
for (int i = 0; i < strIds.length; i++) {
//调用service层进行删除操作
cs.delete(strIds[i]) ;
}
//转向主页面
listAll(request, response) ;
}
//删除单个的客户信息
private void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//拿到页面传递的数据
String id = request.getParameter("id") ;
//调用service层完成业务逻辑
boolean flag = cs.delete(id) ;
if (!flag) {
// 删除失败
request.getSession().setAttribute("error", "删除失败");
}
// 先重新查询数据库,拿取数据后在转向
listAll(request, response);
}
// 修改客户信息
private void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 封装页面的数据
CustomerFormBean cfb = WebUtils.fillFormBean(CustomerFormBean.class,
request);
// 检测数据(省略)
// 拷贝数据到一个JavaBean中
Customer c = new Customer();
// 由于时间是date类型,所以首先注册一个时间转换器
ConvertUtils.register(new DateLocaleConverter(), Date.class);
// 拷贝数据
try {
BeanUtils.copyProperties(c, cfb);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 处理数据
// 其次由于爱好类型不同,所以bean不会膀臂拷贝数据,需要手动拷贝
// 拿到页面的爱好数组
String[] hobby = cfb.getHobby();
if (hobby != null && hobby.length > 0) {
StringBuffer sb = new StringBuffer(hobby[0]);
for (int i = 1; i < hobby.length; i++) {
sb.append("," + hobby[i]);
}
c.setHobby(sb.toString());
}
// 调用service层完成业务逻辑
boolean flag = cs.update(c);
if (flag) {
// 说明修改成功了,转向主页面
// 先重新查询数据库,拿取数据后在转向
listAll(request, response);
} else {
// 修改失败
request.setAttribute("error", "修改失败");
request.getRequestDispatcher("/update.jsp").forward(request, response);
}
}
// 转向修改页面(查出来用户数据后)
private void toUpdate(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// 拿到页面传递的id
String id = request.getParameter("id");
// 调用service层完成业务逻辑(查找用户)
Customer c = cs.findCustomerById(id);
// 将对象存入request对象后转发到修改页面
request.setAttribute("customer", c);
request.getRequestDispatcher("/update.jsp").forward(request, response);
}
// 添加客户信息
private void addCustomer(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// 封装页面的数据
CustomerFormBean cfb = WebUtils.fillFormBean(CustomerFormBean.class,
request);
// 检测数据(省略)
// 拷贝数据到一个JavaBean中
Customer c = new Customer();
// 由于时间是date类型,所以首先注册一个时间转换器
ConvertUtils.register(new DateLocaleConverter(), Date.class);
// 拷贝数据
try {
BeanUtils.copyProperties(c, cfb);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 处理数据
// 首先c中没有主键(id),需要创建一个id
c.setId(WebTools.createNewId());
// 其次由于爱好类型不同,所以bean不会膀臂拷贝数据,需要手动拷贝
// 拿到页面的爱好数组
String[] hobby = cfb.getHobby();
if (hobby != null && hobby.length > 0) {
StringBuffer sb = new StringBuffer(hobby[0]);
for (int i = 1; i < hobby.length; i++) {
sb.append("," + hobby[i]);
}
c.setHobby(sb.toString());
}
// 调用service层完成业务逻辑
boolean flag = cs.add(c);
if (flag) {
// 说明添加成功了,转向主页面
// 先重新查询数据库,拿取数据后在转向
listAll(request, response);
} else {
// 添加失败
request.setAttribute("error", "添加失败");
request.getRequestDispatcher("/add.jsp").forward(request, response);
}
}
// 显示所有的数据
private void listAll(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// 拿到所有的数据
List<Customer> list = cs.getAllCustomer();
// 将数据存放到session中
request.getSession().setAttribute("list", list);
// 页面重定向到主页面
response.sendRedirect(request.getContextPath() + "/list.jsp");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
dbcfg.properties:
index.jsp:
<body>
<jsp:forward page="/servlet/Controller?op=all"></jsp:forward>
</body>list.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri = "http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</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="styles.css">
-->
<style type="text/css">
#t1{
width:900px;
}
#t2{
border:1px solid gray;
border-collapse: collapse;
font-size:15px;
text-align:center;
}
#t2 td,th{
border:1px solid gray;
}
#t2 tr:hover{
background-color: ffccff ;
}
</style>
</head>
<script type="text/javascript">
function checkAll(flag){
//拿到所有的记录
var ids = document.getElementsByName("ids") ;
//循环设置每一个复选框
for(var i = 0 ;i <ids.length ;i++){
ids[i].checked = flag ;
}
}
function delmore(){
//拿到所有的记录的复选框
var ids = document.getElementsByName("ids") ;
//循环判断每一个复选框是否选中,构建id字符串
var s = "" ;
for(var i = 0 ;i<ids.length ;i++){
if(ids[i].checked == true){
//拿到此复选框的value
s += ids[i].value + "," ;
}
}
//数据传递到服务端进行删除
window.location = "${pageContext.request.contextPath }/servlet/Controller?op=delmore&ids=" + s ;
}
</script>
<body>
<h1 align ="center">客户信息</h1>
<hr>
<table id = "t1" align = "center">
<tr>
<td>
<a href = "${pageContext.request.contextPath }/add.jsp">添加</a>
<a href = "javascript:delmore()">删除</a>
</td>
</tr>
<tr>
<td>
<table width = "100%" id = "t2">
<tr>
<th nowrap><input type = "checkbox" id = "all" onclick = "checkAll(this.checked)" >全选全不选</th>
<th nowrap>姓名</th>
<th nowrap>性别</th>
<th nowrap>生日</th>
<th nowrap>电话</th>
<th nowrap>邮箱</th>
<th nowrap>爱好</th>
<th nowrap>类型</th>
<th nowrap>描述</th>
<th nowrap>操作</th>
</tr>
<c:choose>
<c:when test="${empty list}">
<tr>
<td colspan = "10" align = "center">暂时没有数据</td>
</tr>
</c:when>
<c:otherwise>
<c:forEach items="${list }" var = "c" >
<tr>
<td nowrap><input type = "checkbox" name = "ids" value= "${c.id }" ></td>
<td nowrap>${c.name }</td>
<td nowrap>${c.gender=="1"?"男":"女" }</td>
<td nowrap>${c.birthday }</td>
<td nowrap>${c.cellphone}</td>
<td nowrap>${c.email }</td>
<td nowrap>${c.hobby }</td>
<td nowrap>${c.type=="vip"?"贵宾":"普通用户" }</td>
<td nowrap>${c.description }</td>
<td nowrap>
<a href = "${pageContext.request.contextPath }/servlet/Controller?op=toupdate&id=${c.id}">修改</a>
<a href = "${pageContext.request.contextPath }/servlet/Controller?op=delete&id=${c.id}">删除</a>
</td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>
</td>
</tr>
</table>
</body>
</html>
add.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</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">
<script type="text/javascript"
src="${pageContext.request.contextPath }/js/Birthday-Calendar.js"></script>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
#t1{
width: 900px;
}
</style>
</head>
<body>
<h1 align="center">添加客户信息</h1>
<hr>
<form action="${pageContext.request.contextPath }/servlet/Controller?op=add" method="post">
<table id="t1" align="center">
<tr>
<td align="right" width = "40%">姓名:</td>
<td align="left"><input type="text" name="name">
</td>
</tr>
<tr>
<td align="right" width = "40%">性别:</td>
<td align="left"><input type="radio" name="gender" value="1"
checked>男<input type="radio" name="gender" value="0">女</td>
</tr>
<tr>
<td align="right" width = "40%">生日:</td>
<td align="left"><input type="text" name="birthday"
onfocus="new Calendar().show(this)" readonly="readonly">
</td>
</tr>
<tr>
<td align="right" width = "40%">电话:</td>
<td align="left"><input type="text" name="cellphone">
</td>
</tr>
<tr>
<td align="right" width = "40%">邮箱:</td>
<td align="left"><input type="text" name="email">
</td>
</tr>
<tr>
<td align="right" width = "40%">爱好:</td>
<td align="left"><input type="checkbox" name="hobby"
value="吃饭">吃饭 <input type="checkbox" name="hobby"
value="睡觉">睡觉 <input type="checkbox" name="hobby"
value="学java">学Java</td>
</tr>
<tr>
<td align="right" width = "40%">类型:</td>
<td align="left"><input type="radio" name="type" value="vip"
checked>贵宾 <input type="radio" name="type" value="common">普通用户
</td>
</tr>
<tr>
<td align="right" width = "40%">描述:</td>
<td align="left"><textarea rows="5" cols="20"
name="description">大神留点脚印吧!!!</textarea></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" value="添加">
</td>
</tr>
</table>
</form>
</body>
</html>
update.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fun"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</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">
<script type="text/javascript"
src="${pageContext.request.contextPath }/js/Birthday-Calendar.js"></script>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
#t1{
width: 900px;
}
</style>
</head>
<body>
<h1 align="center">修改客户信息</h1>
<hr>
<form action="${pageContext.request.contextPath }/servlet/Controller?op=update" method="post">
<table id="t1" align="center">
<tr>
<td align="left" colspan = "2"><input type="hidden" name="id" value = "${customer.id }">
</td>
</tr>
<tr>
<td align="right" width = "40%">姓名:</td>
<td align="left"><input type="text" name="name" value = "${customer.name }">
</td>
</tr>
<tr>
<td align="right" width = "40%">性别:</td>
<td align="left">
<input type="radio" name="gender" value="1" ${customer.gender=="1"?"checked":"" }>男
<input type="radio" name="gender" value="0" ${customer.gender=="0"?"checked":"" }>女</td>
</tr>
<tr>
<td align="right" width = "40%">生日:</td>
<td align="left"><input type="text" name="birthday"
onfocus="new Calendar().show(this)" readonly="readonly" value = "${customer.birthday }">
</td>
</tr>
<tr>
<td align="right" width = "40%">电话:</td>
<td align="left"><input type="text" name="cellphone" value = "${customer.cellphone }">
</td>
</tr>
<tr>
<td align="right" width = "40%">邮箱:</td>
<td align="left"><input type="text" name="email" value = "${customer.email }">
</td>
</tr>
<tr>
<td align="right" width = "40%">爱好:</td>
<td align="left">
<input type="checkbox" name="hobby" value="吃饭" ${fun:contains(customer.hobby,"吃饭")?"checked":"" }>吃饭
<input type="checkbox" name="hobby" value="睡觉" ${fun:contains(customer.hobby,"睡觉")?"checked":"" }>睡觉
<input type="checkbox" name="hobby" value="学java" ${fun:contains(customer.hobby,"学java")?"checked":"" }>学Java</td>
</tr>
<tr>
<td align="right" width = "40%">类型:</td>
<td align="left">
<input type="radio" name="type" value="vip" ${customer.type=="vip"?"checked":"" }>贵宾
<input type="radio" name="type" value="common" ${customer.type!="vip"?"checked":"" }>普通用户
</td>
</tr>
<tr>
<td align="right" width = "40%">描述:</td>
<td align="left"><textarea rows="5" cols="20"
name="description">${customer.description }</textarea></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" value="保存">
</td>
</tr>
</table>
</form>
</body>
</html>
package com.heima.bean;
import java.io.Serializable;
import java.util.Date;
//create table customer(
// id varchar(100) primary key,
// name varchar(100),
// gender varchar(4),# 1 male 0 female
// birthday date,
// cellphone varchar(20),
// email varchar(40),
// hobby varchar(100),#eat,sleep
// type varchar(40),#vip|normal
// description varchar(255)
// );
public class Customer implements Serializable{
private String id ;
private String name ;
private String gender ;
private Date birthday ;
private String cellphone ;
private String email ;
private String hobby ;
private String type ;
private String description ;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date 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 getHobby() {
return hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
formbean:
package com.heima.web.formbean;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
public class CustomerFormBean implements Serializable{
private String id ;
private String name ;
private String gender ;
private String birthday ;
private String cellphone ;
private String email ;
private String[] hobby ;
private String type ;
private String description ;
private Map<String,String> errors = new HashMap<String,String>() ;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
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[] getHobby() {
return hobby;
}
public void setHobby(String[] hobby) {
this.hobby = hobby;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean validate(){
//省略
return true ;
}
}
dao:
package com.heima.dao;
import java.util.List;
import com.heima.bean.Customer;
public interface CustomerDao {
/**
* 添加一个客户
* @param customer 要添加的客户
* @return 天成成功返回TRUE,否则返回FALSE
*/
public boolean add(Customer customer) ;
/**
* 修改一个客户
* @param customer 要修改的客户
* @return 成功返回TRUE,否则返回FALSE
*/
public boolean update(Customer customer) ;
/**
* 根据客户的主键删除客户
* @param id 要删除客户的编号
* @return 删除成功返回TRUE,否则返回FALSE
*/
public boolean delete(String id) ;
/**
* 获取所有的客户
* @return 返回所有客户的集合
*/
public List<Customer> getAllCustomer() ;
/**
* 根据客户的编号查询客户
* @param id 客户的编号
* @return 查出来返回此客户,否则返回null
*/
public Customer findCustomerById(String id) ;
}
utils:
JdbcUtils:
package com.heima.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;
//专门用于数据库的工具类
public class JdbcUtils {
private static String driverClass = "" ;
private static String url = "" ;
private static String user = "" ;
private static String password = "";
static{
ResourceBundle rb = ResourceBundle.getBundle("dbcfg") ;
driverClass = rb.getString("driverClass") ;
url = rb.getString("url") ;
user = rb.getString("user") ;
password = rb.getString("password") ;
try {
Class.forName(driverClass) ;
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConnection(){
try {
return DriverManager.getConnection(url, user, password) ;
} catch (SQLException e) {
e.printStackTrace();
}
return null ;
}
public static void release(ResultSet rs ,Statement stmt,Connection conn){
if(rs != null){
try {
rs.close() ;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(stmt != null){
try {
stmt.close() ;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(conn != null){
try {
conn.close() ;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
WebUtils:
package com.heima.utils;
import java.lang.reflect.InvocationTargetException;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.beanutils.BeanUtils;
//专门为页面服务: 封装了页面的信息
public class WebUtils {
public static <T> T fillFormBean(Class<T> clazz,HttpServletRequest request){
T t = null ;
try {
t = clazz.newInstance() ;
BeanUtils.populate(t, request.getParameterMap()) ;
} catch (Exception e) {
e.printStackTrace();
}
return t ;
}
}
WebTools:
package com.heima.utils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;
import sun.misc.BASE64Encoder;
//用来做一些常用的一些操作
public class WebTools {
//获取一个新的唯一的id
public static String createNewId(){
String id = UUID.randomUUID().toString() ;
MessageDigest md;
try {
md = MessageDigest.getInstance("md5");
byte[] bs = md.digest(id.getBytes()) ;
BASE64Encoder base = new BASE64Encoder() ;
id = base.encode(bs) ;
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return id ;
}
}
dao.impl:
package com.heima.dao.impl; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.heima.bean.Customer; import com.heima.dao.CustomerDao; import com.heima.utils.JdbcUtils; public class CustomerDaoImpl implements CustomerDao { public boolean add(Customer customer) { // 拿到连接对象 Connection conn = JdbcUtils.getConnection(); PreparedStatement pstmt = null; // 创建预处理命令对象 int n = 0; try { pstmt = conn .prepareStatement("insert into " + "customer(id,name,gender,birthday,cellphone,email,hobby,type,description) values(?,?,?,?,?,?,?,?,?)"); // 指定?的值 pstmt.setString(1, customer.getId()); pstmt.setString(2, customer.getName()); pstmt.setString(3, customer.getGender()); pstmt.setDate(4, new java.sql.Date(customer.getBirthday().getTime())); pstmt.setString(5, customer.getCellphone()); pstmt.setString(6, customer.getEmail()); pstmt.setString(7, customer.getHobby()); pstmt.setString(8, customer.getType()); pstmt.setString(9, customer.getDescription()); // 执行sql语句 n = pstmt.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { JdbcUtils.release(null, pstmt, conn); } return n > 0 ? true : false; } public boolean update(Customer customer) { // 拿到连接对象 Connection conn = JdbcUtils.getConnection(); PreparedStatement pstmt = null; // 创建预处理命令对象 int n = 0; try { pstmt = conn .prepareStatement("update customer set name=?,gender=?,birthday=?,cellphone=?,email=?,hobby=?,type=?,description=? where id = ?"); // 指定?的值 pstmt.setString(1, customer.getName()); pstmt.setString(2, customer.getGender()); pstmt.setDate(3, new java.sql.Date(customer.getBirthday().getTime())); pstmt.setString(4, customer.getCellphone()); pstmt.setString(5, customer.getEmail()); pstmt.setString(6, customer.getHobby()); pstmt.setString(7, customer.getType()); pstmt.setString(8, customer.getDescription()); pstmt.setString(9, customer.getId()); // 执行sql语句 n = pstmt.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { JdbcUtils.release(null, pstmt, conn); } return n > 0 ? true : false; } public boolean delete(String id) { // 拿到连接对象 Connection conn = JdbcUtils.getConnection(); PreparedStatement pstmt = null; // 创建预处理命令对象 int n = 0; try { pstmt = conn.prepareStatement("delete from customer where id = ?"); // 指定?的值 pstmt.setString(1, id); // 执行sql语句 n = pstmt.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { JdbcUtils.release(null, pstmt, conn); } return n > 0 ? true : false; } public List<Customer> getAllCustomer() { // 拿到连接对象 Connection conn = JdbcUtils.getConnection(); PreparedStatement pstmt = null; ResultSet rs = null; List<Customer> list = new ArrayList<Customer>(); // 创建预处理命令对象 try { pstmt = conn .prepareStatement("select id,name,gender,birthday,cellphone,email,hobby,type,description from customer"); // 执行sql语句 rs = pstmt.executeQuery(); while (rs.next()) { // 封装数据 Customer c = new Customer(); try { String id = URLEncoder.encode(rs.getString("id"), "UTF-8"); c.setId(id); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } c.setName(rs.getString("name")); c.setGender(rs.getString("gender")); c.setBirthday(rs.getDate("birthday")); c.setCellphone(rs.getString("cellphone")); c.setEmail(rs.getString("email")); c.setHobby(rs.getString("hobby")); c.setType(rs.getString("type")); c.setDescription(rs.getString("description")); list.add(c); } } catch (SQLException e) { e.printStackTrace(); } finally { JdbcUtils.release(null, pstmt, conn); } return list; } public Customer findCustomerById(String id) { // 拿到连接对象 Connection conn = JdbcUtils.getConnection(); PreparedStatement pstmt = null; ResultSet rs = null; // 创建预处理命令对象 try { pstmt = conn .prepareStatement("select id,name,gender,birthday,cellphone,email,hobby,type,description from customer where id = '" + id + "'"); // 执行sql语句 rs = pstmt.executeQuery(); if (rs.next()) { // 封装数据 Customer c = new Customer(); c.setId(rs.getString("id")); c.setName(rs.getString("name")); c.setGender(rs.getString("gender")); c.setBirthday(rs.getDate("birthday")); c.setCellphone(rs.getString("cellphone")); c.setEmail(rs.getString("email")); c.setHobby(rs.getString("hobby")); c.setType(rs.getString("type")); c.setDescription(rs.getString("description")); return c; } } catch (SQLException e) { e.printStackTrace(); } finally { JdbcUtils.release(null, pstmt, conn); } return null; } }
service:
package com.heima.service;
import java.util.List;
import com.heima.bean.Customer;
public interface CustomerService {
/**
* 添加一个客户
* @param customer 要天剑的客户
* @return 天成成功返回TRUE,否则返回FALSE
*/
public boolean add(Customer customer) ;
/**
* 修改一个客户
* @param customer 要修改的客户
* @return 成功返回TRUE,否则返回FALSE
*/
public boolean update(Customer customer) ;
/**
* 根据客户的主键删除客户
* @param id 要删除客户的编号
* @return 删除成功返回TRUE,否则返回FALSE
*/
public boolean delete(String id) ;
/**
* 获取所有的客户
* @return 返回所有客户的集合
*/
public List<Customer> getAllCustomer() ;
/**
* 根据客户的编号查询客户
* @param id 客户的编号
* @return 查出来返回此客户,否则返回null
*/
public Customer findCustomerById(String id) ;
}
service.iimpl:
package com.heima.service.impl; import java.util.List; import com.heima.bean.Customer; import com.heima.dao.CustomerDao; import com.heima.dao.impl.CustomerDaoImpl; import com.heima.service.CustomerService; public class CustomerServiceImpl implements CustomerService { CustomerDao dao = new CustomerDaoImpl() ; public boolean add(Customer customer) { return dao.add(customer); } public boolean update(Customer customer) { return dao.update(customer); } public boolean delete(String id) { return dao.delete(id); } public List<Customer> getAllCustomer() { return dao.getAllCustomer(); } public Customer findCustomerById(String id) { return dao.findCustomerById(id); } }web.Servlet:
Controller:
package com.heima.web.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.locale.converters.DateLocaleConverter;
import com.heima.bean.Customer;
import com.heima.service.CustomerService;
import com.heima.service.impl.CustomerServiceImpl;
import com.heima.utils.WebTools;
import com.heima.utils.WebUtils;
import com.heima.web.formbean.CustomerFormBean;
//控制请求的转向(流程控制)(前端控制器)
public class Controller extends HttpServlet {
CustomerService cs = new CustomerServiceImpl();
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
// 拿到页面传递的数据
String op = request.getParameter("op");
if ("all".equals(op)) {
listAll(request, response);
} else if ("add".equals(op)) {
addCustomer(request, response);
} else if ("toupdate".equals(op)) {
toUpdate(request, response);
} else if ("update".equals(op)) {
update(request, response);
} else if("delete".equals(op)){
delete(request,response) ;
} else if("delmore".equals(op)){
delMore(request,response) ;
}
}
//删除多条数据
private void delMore(HttpServletRequest request,
HttpServletResponse response)throws ServletException, IOException {
//拿到页面的数据
String ids = request.getParameter("ids") ;
//由于ids后面多了一个逗号,记得去掉
ids = ids.substring(0, ids.length()-1) ;
//拆分字符串
String [] strIds = ids.split(",") ;
System.out.println(strIds[0]);
//循环删除
for (int i = 0; i < strIds.length; i++) {
//调用service层进行删除操作
cs.delete(strIds[i]) ;
}
//转向主页面
listAll(request, response) ;
}
//删除单个的客户信息
private void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//拿到页面传递的数据
String id = request.getParameter("id") ;
//调用service层完成业务逻辑
boolean flag = cs.delete(id) ;
if (!flag) {
// 删除失败
request.getSession().setAttribute("error", "删除失败");
}
// 先重新查询数据库,拿取数据后在转向
listAll(request, response);
}
// 修改客户信息
private void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 封装页面的数据
CustomerFormBean cfb = WebUtils.fillFormBean(CustomerFormBean.class,
request);
// 检测数据(省略)
// 拷贝数据到一个JavaBean中
Customer c = new Customer();
// 由于时间是date类型,所以首先注册一个时间转换器
ConvertUtils.register(new DateLocaleConverter(), Date.class);
// 拷贝数据
try {
BeanUtils.copyProperties(c, cfb);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 处理数据
// 其次由于爱好类型不同,所以bean不会膀臂拷贝数据,需要手动拷贝
// 拿到页面的爱好数组
String[] hobby = cfb.getHobby();
if (hobby != null && hobby.length > 0) {
StringBuffer sb = new StringBuffer(hobby[0]);
for (int i = 1; i < hobby.length; i++) {
sb.append("," + hobby[i]);
}
c.setHobby(sb.toString());
}
// 调用service层完成业务逻辑
boolean flag = cs.update(c);
if (flag) {
// 说明修改成功了,转向主页面
// 先重新查询数据库,拿取数据后在转向
listAll(request, response);
} else {
// 修改失败
request.setAttribute("error", "修改失败");
request.getRequestDispatcher("/update.jsp").forward(request, response);
}
}
// 转向修改页面(查出来用户数据后)
private void toUpdate(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// 拿到页面传递的id
String id = request.getParameter("id");
// 调用service层完成业务逻辑(查找用户)
Customer c = cs.findCustomerById(id);
// 将对象存入request对象后转发到修改页面
request.setAttribute("customer", c);
request.getRequestDispatcher("/update.jsp").forward(request, response);
}
// 添加客户信息
private void addCustomer(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// 封装页面的数据
CustomerFormBean cfb = WebUtils.fillFormBean(CustomerFormBean.class,
request);
// 检测数据(省略)
// 拷贝数据到一个JavaBean中
Customer c = new Customer();
// 由于时间是date类型,所以首先注册一个时间转换器
ConvertUtils.register(new DateLocaleConverter(), Date.class);
// 拷贝数据
try {
BeanUtils.copyProperties(c, cfb);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 处理数据
// 首先c中没有主键(id),需要创建一个id
c.setId(WebTools.createNewId());
// 其次由于爱好类型不同,所以bean不会膀臂拷贝数据,需要手动拷贝
// 拿到页面的爱好数组
String[] hobby = cfb.getHobby();
if (hobby != null && hobby.length > 0) {
StringBuffer sb = new StringBuffer(hobby[0]);
for (int i = 1; i < hobby.length; i++) {
sb.append("," + hobby[i]);
}
c.setHobby(sb.toString());
}
// 调用service层完成业务逻辑
boolean flag = cs.add(c);
if (flag) {
// 说明添加成功了,转向主页面
// 先重新查询数据库,拿取数据后在转向
listAll(request, response);
} else {
// 添加失败
request.setAttribute("error", "添加失败");
request.getRequestDispatcher("/add.jsp").forward(request, response);
}
}
// 显示所有的数据
private void listAll(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// 拿到所有的数据
List<Customer> list = cs.getAllCustomer();
// 将数据存放到session中
request.getSession().setAttribute("list", list);
// 页面重定向到主页面
response.sendRedirect(request.getContextPath() + "/list.jsp");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
dbcfg.properties:
index.jsp:
<body>
<jsp:forward page="/servlet/Controller?op=all"></jsp:forward>
</body>list.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri = "http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</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="styles.css">
-->
<style type="text/css">
#t1{
width:900px;
}
#t2{
border:1px solid gray;
border-collapse: collapse;
font-size:15px;
text-align:center;
}
#t2 td,th{
border:1px solid gray;
}
#t2 tr:hover{
background-color: ffccff ;
}
</style>
</head>
<script type="text/javascript">
function checkAll(flag){
//拿到所有的记录
var ids = document.getElementsByName("ids") ;
//循环设置每一个复选框
for(var i = 0 ;i <ids.length ;i++){
ids[i].checked = flag ;
}
}
function delmore(){
//拿到所有的记录的复选框
var ids = document.getElementsByName("ids") ;
//循环判断每一个复选框是否选中,构建id字符串
var s = "" ;
for(var i = 0 ;i<ids.length ;i++){
if(ids[i].checked == true){
//拿到此复选框的value
s += ids[i].value + "," ;
}
}
//数据传递到服务端进行删除
window.location = "${pageContext.request.contextPath }/servlet/Controller?op=delmore&ids=" + s ;
}
</script>
<body>
<h1 align ="center">客户信息</h1>
<hr>
<table id = "t1" align = "center">
<tr>
<td>
<a href = "${pageContext.request.contextPath }/add.jsp">添加</a>
<a href = "javascript:delmore()">删除</a>
</td>
</tr>
<tr>
<td>
<table width = "100%" id = "t2">
<tr>
<th nowrap><input type = "checkbox" id = "all" onclick = "checkAll(this.checked)" >全选全不选</th>
<th nowrap>姓名</th>
<th nowrap>性别</th>
<th nowrap>生日</th>
<th nowrap>电话</th>
<th nowrap>邮箱</th>
<th nowrap>爱好</th>
<th nowrap>类型</th>
<th nowrap>描述</th>
<th nowrap>操作</th>
</tr>
<c:choose>
<c:when test="${empty list}">
<tr>
<td colspan = "10" align = "center">暂时没有数据</td>
</tr>
</c:when>
<c:otherwise>
<c:forEach items="${list }" var = "c" >
<tr>
<td nowrap><input type = "checkbox" name = "ids" value= "${c.id }" ></td>
<td nowrap>${c.name }</td>
<td nowrap>${c.gender=="1"?"男":"女" }</td>
<td nowrap>${c.birthday }</td>
<td nowrap>${c.cellphone}</td>
<td nowrap>${c.email }</td>
<td nowrap>${c.hobby }</td>
<td nowrap>${c.type=="vip"?"贵宾":"普通用户" }</td>
<td nowrap>${c.description }</td>
<td nowrap>
<a href = "${pageContext.request.contextPath }/servlet/Controller?op=toupdate&id=${c.id}">修改</a>
<a href = "${pageContext.request.contextPath }/servlet/Controller?op=delete&id=${c.id}">删除</a>
</td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>
</td>
</tr>
</table>
</body>
</html>
add.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</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">
<script type="text/javascript"
src="${pageContext.request.contextPath }/js/Birthday-Calendar.js"></script>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
#t1{
width: 900px;
}
</style>
</head>
<body>
<h1 align="center">添加客户信息</h1>
<hr>
<form action="${pageContext.request.contextPath }/servlet/Controller?op=add" method="post">
<table id="t1" align="center">
<tr>
<td align="right" width = "40%">姓名:</td>
<td align="left"><input type="text" name="name">
</td>
</tr>
<tr>
<td align="right" width = "40%">性别:</td>
<td align="left"><input type="radio" name="gender" value="1"
checked>男<input type="radio" name="gender" value="0">女</td>
</tr>
<tr>
<td align="right" width = "40%">生日:</td>
<td align="left"><input type="text" name="birthday"
onfocus="new Calendar().show(this)" readonly="readonly">
</td>
</tr>
<tr>
<td align="right" width = "40%">电话:</td>
<td align="left"><input type="text" name="cellphone">
</td>
</tr>
<tr>
<td align="right" width = "40%">邮箱:</td>
<td align="left"><input type="text" name="email">
</td>
</tr>
<tr>
<td align="right" width = "40%">爱好:</td>
<td align="left"><input type="checkbox" name="hobby"
value="吃饭">吃饭 <input type="checkbox" name="hobby"
value="睡觉">睡觉 <input type="checkbox" name="hobby"
value="学java">学Java</td>
</tr>
<tr>
<td align="right" width = "40%">类型:</td>
<td align="left"><input type="radio" name="type" value="vip"
checked>贵宾 <input type="radio" name="type" value="common">普通用户
</td>
</tr>
<tr>
<td align="right" width = "40%">描述:</td>
<td align="left"><textarea rows="5" cols="20"
name="description">大神留点脚印吧!!!</textarea></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" value="添加">
</td>
</tr>
</table>
</form>
</body>
</html>
update.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fun"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</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">
<script type="text/javascript"
src="${pageContext.request.contextPath }/js/Birthday-Calendar.js"></script>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
#t1{
width: 900px;
}
</style>
</head>
<body>
<h1 align="center">修改客户信息</h1>
<hr>
<form action="${pageContext.request.contextPath }/servlet/Controller?op=update" method="post">
<table id="t1" align="center">
<tr>
<td align="left" colspan = "2"><input type="hidden" name="id" value = "${customer.id }">
</td>
</tr>
<tr>
<td align="right" width = "40%">姓名:</td>
<td align="left"><input type="text" name="name" value = "${customer.name }">
</td>
</tr>
<tr>
<td align="right" width = "40%">性别:</td>
<td align="left">
<input type="radio" name="gender" value="1" ${customer.gender=="1"?"checked":"" }>男
<input type="radio" name="gender" value="0" ${customer.gender=="0"?"checked":"" }>女</td>
</tr>
<tr>
<td align="right" width = "40%">生日:</td>
<td align="left"><input type="text" name="birthday"
onfocus="new Calendar().show(this)" readonly="readonly" value = "${customer.birthday }">
</td>
</tr>
<tr>
<td align="right" width = "40%">电话:</td>
<td align="left"><input type="text" name="cellphone" value = "${customer.cellphone }">
</td>
</tr>
<tr>
<td align="right" width = "40%">邮箱:</td>
<td align="left"><input type="text" name="email" value = "${customer.email }">
</td>
</tr>
<tr>
<td align="right" width = "40%">爱好:</td>
<td align="left">
<input type="checkbox" name="hobby" value="吃饭" ${fun:contains(customer.hobby,"吃饭")?"checked":"" }>吃饭
<input type="checkbox" name="hobby" value="睡觉" ${fun:contains(customer.hobby,"睡觉")?"checked":"" }>睡觉
<input type="checkbox" name="hobby" value="学java" ${fun:contains(customer.hobby,"学java")?"checked":"" }>学Java</td>
</tr>
<tr>
<td align="right" width = "40%">类型:</td>
<td align="left">
<input type="radio" name="type" value="vip" ${customer.type=="vip"?"checked":"" }>贵宾
<input type="radio" name="type" value="common" ${customer.type!="vip"?"checked":"" }>普通用户
</td>
</tr>
<tr>
<td align="right" width = "40%">描述:</td>
<td align="left"><textarea rows="5" cols="20"
name="description">${customer.description }</textarea></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" value="保存">
</td>
</tr>
</table>
</form>
</body>
</html>
相关文章推荐
- 客户(用户)管理系统---基于数据库javaweb的增删改查
- 通用客户资源管理系统(客户资料保护库)
- 客户管理系统CRM 专业商业版 下载
- "客户管理系统"终于开发完毕,在这快乐元宵节里深吸一口气(图)
- 客户接触管理系统项目总结
- 工作流管理在自来水营销管理系统(客户服务中心)中的应用(原创)
- 客户资源管理系统
- 客户售后服务工作单管理系统 下载
- 客户管理系统 官网
- 基于SSH的黄页广告客户管理系统
- 协拓crm客户管理及客户跟踪管理系统 v6.8 官方
- 九天客户管理系统 2005 网络版 官网
- 九天客户管理系统 2005 精简版 官网
- 中普客户销售管理系统 破解软件
- 自己写了个客户管理系统,免费提供!
- 精英客户服务管理系统 怎么用
- 健身俱乐部客户管理系统 是什么
- 省 VIP 客户业务管理系统概述 (DELPHI + TUXEDO -&gt; JAVA[Spring])
- 以CRM系统管理客户 突破“求救无门”困局