欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java web個人通訊錄系統(tǒng)設(shè)計

 更新時間:2020年07月24日 14:40:40   作者:kang_ya_ping  
這篇文章主要為大家詳細介紹了java web個人通訊錄系統(tǒng)設(shè)計,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了java web個人通訊錄系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

現(xiàn)在開始上截圖:

下面粘貼代碼:

首先是目錄結(jié)構(gòu):

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <title>add.jsp</title>
 <script type="text/javascript" src="<c:url value='/jquery/contactor.js'/>"></script> 
 
  <style type="text/css">
 body{
  text-align: center;
  font-size:38px;
 }
   *{
   font-family:華文楷體;
   font-size:18px;
   color:#F0F";
 }
 h1{
  text-align: center;
  font-size:38px;
 }
 </style>
  
 </head>
 
 <body >
 
 <h1 style="font-size:38px;">添加新的聯(lián)系人</h1>
 
 <form action="<c:url value='/ContactorServlet?userId=${userId } '/>" method="post" onsubmit="return checkForm()">
  <input type="hidden" name="method" value="4">
  <table border="1" width="50%" align="center">
   <tr>
    <td>姓名</td>
    <td>
     <input type="text" name="name" id="name" onfocus="nameFocus()" onblur="nameBlur()"/>
     <div id="nameId"></div>
    </td>
   </tr>
   <tr>
    <td>電話</td>
    <td>
     <input type="text" name="tel" id="tel" onfocus="telFocus()" onblur="telBlur()"/>
     <div id="telId"></div>
    </td>
   </tr>
   <tr>
    <td>地址</td>
    <td>
     <input type="text" name="address" id="address" />
    </td>
   </tr>  
    <tr>
    <td>郵編</td>
    <td>
     <input type="text" name="zipcode" />
    </td>
   </tr>
  
     
  </table>
  <input style="margin-right:200px;" type="submit" value="添加"/> 
    
 </form>
 </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <title>edit.jsp</title>

 <script type="text/javascript" src="<c:url value='/jquery/contactor.js'/>"></script> 
 
 
  <style type="text/css">
 body{
  text-align: center;
  font-size:38px;
 }
   *{
   font-family:華文楷體;
   font-size:18px;
   color:#F0F";
 }
 h1{
  text-align: center;
  font-size:38px;
 }
 </style>
  
 </head>
 
 <body > 
 <h1 style="font-size:38px;">修改聯(lián)系人信息</h1>
 <form action="<c:url value='/ContactorServlet'/>" method="post" onsubmit="return checkForm()">
  <input type="hidden" name="method" value="6">
  <input type="hidden" name="id" value="${contactor.id }">
  <table border="1" width="50%" align="center">
   <tr>
    <td>姓名</td>
    <td>
     <input type="text" name="name" value="${contactor.name }" id="name" onfocus="nameFocus()" onblur="nameBlur()"/>
     <div id="nameId"></div>
    </td>
   </tr>
   <tr>
    <td>電話</td>
    <td>
     <input type="text" name="tel" value="${contactor.tel }" id="tel" onfocus="telFocus()" onblur="telBlur()" />
     <div id="telId"></div>
    </td>
   </tr>
   <tr>
    <td>地址</td>
    <td>
     <input type="text" id="address" name="address" value="${contactor.address }" />
    </td>
   </tr>  
    <tr>
    <td>郵編</td>
    <td>
     <input type="text" name="zipcode" value="${contactor.zipcode }" />
    </td>
   </tr> 
   
  </table>
  <input style="margin-right:200px;" type="submit" value="更改"/>
     
   
 </form>
 </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <title>home.jsp</title>
 </head>
 
<frameset rows="100%,*">
 
 <frame name="body" src="<c:url value='/jsp/top.jsp'/>" />
</frameset>
</html>

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <title>list.jsp</title> 
  <style type="text/css">
 body{
  text-align: center;
  font-size:38px;
 }
   *{
   font-family:華文楷體;
   font-size:18px;
   color:#F0F";
 }
 h1{
  text-align: center;
  font-size:38px;
 }
 a:link{
  color: #999;
  text-decoration: none;
 }
 a:VISITED {
 text-decoration: none;
 color: #c60;
}
 a:HOVER {
 text-decoration: none;
 color: #00F;
}
 </style>
  
 </head>
 
 <body >
 <h1 style="font-size:38px;">歡迎登錄到通信錄系統(tǒng)</h1>
 <a style="font-size:26px;" href="<c:url value='/ContactorServlet?method=3&userId=${userId }'/>">查看聯(lián)系人</a>
 <a style="font-size:26px;" href="<c:url value='/jsp/add.jsp'/>">添加聯(lián)系人</a>
 <a  style="font-size:26px;" href="<c:url value='/jsp/top.jsp'/>">退出系統(tǒng)</a>
 
 <table border="1" align="center" width="60%">
  <tr>
   <th>姓名</th>
   <th>電話</th>
   <th>地址</th>
   <th>郵編</th>
   <th>操作1</th>
   <th>操作2</th>
   
  </tr>
  <c:forEach items="${contactorList }" var="c">
  <tr>
   <td>${c.name }</td>
   <td>${c.tel }</td>
   <td>${c.address }</td>
   <td>${c.zipcode }</td>
   
   <td><a href="<c:url value='/ContactorServlet?method=5&id=${c.id }'/>">編輯</a>
   </td>
   <td>
    <a href="<c:url value='/ContactorServlet?method=7&id=${c.id }'/>" >刪除</a>
   </td>
  </tr>
  </c:forEach>
 </table>
 </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <title>top.jsp</title>
  <style type="text/css">
 body{
  text-align: center;
  font-size:38px;
 }
   *{
   font-family:華文楷體;
   font-size:18px;
   color:#F0F";
 }
 h1{
  text-align: center;
  font-size:38px;
 }
 </style>
 
 </head>
 
 <body >
 <h1 style="font-size:38px;">我的通信錄</h1>
  
 <form action="<c:url value='/ContactorServlet'/>" method="post">
   <input type="hidden" name="method" value="1"> 
  用戶名:<input type="text" name="username" /><br/>
  密 &nbsp; 碼:<input type="password" name="password" /><br/>
  <input type="submit" value="注冊">
 </form>
 </body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <title>top.jsp</title>
  <style type="text/css">
 body{
  text-align: center;
  font-size:38px;
 }
   *{
   font-family:華文楷體;
   font-size:18px;
   color:#F0F";
 }
 h1{
  text-align: center;
  font-size:38px;
 }
 </style>
 </head>
 
 <body >
 <h1 style="font-size:38px;">我的通信錄</h1>
  
 <form action="<c:url value='/ContactorServlet'/>" method="post">
  <input type="hidden" name="method" value="2"> 
  用戶名:<input type="text" name="username"/><br/>
  密 &nbsp; 碼:<input type="password" name="password"/><br/>
  <input type="submit" value="登錄">
 <a href="<c:url value='/jsp/register.jsp'/>" target="body" >注冊</a>
 </form>
 </body>
</html>

index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<jsp:forward page="/jsp/home.jsp" />

contactor.js

//當鼠標放在客戶名文本框時,給出一個提示文本
function nameFocus() {
 var nameId = document.getElementById("nameId");
 nameId.innerHTML = "請輸入客戶真實姓名";
}
//當鼠標離開客戶名文本框時,給出一個文本提示
function nameBlur() {
 var name = document.getElementById("name");
 var nameId = document.getElementById("nameId");
 var reg= /^[\u4e00-\u9fa5]+$/;
 if(name.value == ""){
  nameId.innerHTML = "<font color='red'>聯(lián)系人名不能為空</font>";
  return false;
 }
 if(reg.test(name.value) == false){
  nameId.innerHTML = "<font color='red'>聯(lián)系人名只能輸入中文簡體漢字</font>";
  return false;
 }
 nameId.innerHTML = "<font color='green'>聯(lián)系人名輸入正確</font>";
 return true;
 
}
//當鼠標放在客戶名文本框時,給出一個提示文本
function telFocus() {
 var telId = document.getElementById("telId");
 telId.innerHTML = "請輸入手機號碼";
}

//當鼠標離開客戶名文本框時,給出一個文本提示
function telBlur() {
 var tel = document.getElementById("tel");
 var telId = document.getElementById("telId");
 var reg= /^(13|15|17|18)\d{9}$/;
 if(tel.value == ""){
  telId.innerHTML = "<font color='red'>手機號碼不能為空</font>";
  return false;
 }
 if(reg.test(tel.value) == false){
  telId.innerHTML = "<font color='red'>手機號碼輸入不正確</font>";
  return false;
 }
 telId.innerHTML = "<font color='green'>手機號碼輸入正確</font>";
 return true;
 
}

//表單提交時驗證輸入內(nèi)容的有效性
function checkForm() {
 var flagname = nameBlur();
 var flagtel = telBlur();
 if(flagname == true && flagtel == true ){
  return true;
 }else{
  alert("失敗,請按提示輸入信息 !")
  return false;
 }
 
 
}
package cn.edu.aynu.rjxy.bean;
/**
 * 聯(lián)系人表屬性
 * @author Administrator
 *
 */
public class Contactor {
 private int id;
 private int userId;
 private String name;
 private String tel;
 private String address;
 private String zipcode;
 
 public int getId() {
  return id;
 }
 public void setId(int id) {
  this.id = id;
 }
 public int getUserId() {
  return userId;
 }
 public void setUserId(int userId) {
  this.userId = userId;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getTel() {
  return tel;
 }
 public void setTel(String tel) {
  this.tel = tel;
 }
 public String getAddress() {
  return address;
 }
 public void setAddress(String address) {
  this.address = address;
 }
 public String getZipcode() {
  return zipcode;
 }
 public void setZipcode(String zipcode) {
  this.zipcode = zipcode;
 }
 
 
}
package cn.edu.aynu.rjxy.bean;
/**
 * 用戶表屬性
 * @author Administrator
 *
 */
public class User {
 private int id;
 private String username;
 private String password;
 public int getId() {
  return id;
 }
 public void setId(int id) {
  this.id = id;
 }
 public String getUsername() {
  return username;
 }
 public void setUsername(String username) {
  this.username = username;
 }
 public String getPassword() {
  return password;
 }
 public void setPassword(String password) {
  this.password = password;
 }
 
 
}
package cn.edu.aynu.rjxy.dao;

import java.sql.SQLException;
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 cn.edu.aynu.rjxy.bean.Contactor;
import cn.edu.aynu.rjxy.utils.JDBCUtils;

/**
 * 對linkman表的增刪改查
 * @author Administrator
 *
 */
public class ContactorDao {
 private QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
 /**
  * 添加聯(lián)系人
  * @param c
  * @throws SQLException 
  */
 public void insert(Contactor c,int userId) throws SQLException{
  String sql = "insert into linkman(name,tel,address,zipcode,userId) values(?,?,?,?,?)";
  qr.update(sql, c.getName(),c.getTel(),c.getAddress(),c.getZipcode(),userId);
 }
 /**
  * 刪除聯(lián)系人
  * @param cid
  * @throws SQLException
  */
 public void delete(int id) throws SQLException{
  String sql = "delete from linkman where id=?";
  qr.update(sql, id);
 }
 /**
  * 修改聯(lián)系人
  * @param c
  * @throws SQLException
  */
 public void update(Contactor c,int userId) throws SQLException{
  String sql = "update linkman set name=?,tel=?,address=?,zipcode=?,userId=? where id=?";
  qr.update(sql, c.getName(),c.getTel(),c.getAddress(),c.getZipcode(),userId,c.getId());
 }
 /**
  * 根據(jù)userId查詢聯(lián)系人
  * @throws SQLException 
  * 
  */
 public List<Contactor> findAll(int userId) throws SQLException{
  String sql = "select * from linkman where userId = ?";
  List<Contactor> list = qr.query(sql, new BeanListHandler<Contactor>(Contactor.class),userId);
  return list;
  
 }
 /**
  * 根據(jù)id查詢某個聯(lián)系人
  * @throws SQLException 
  * 
  */
 public Contactor findByCid(int id) throws SQLException{
  String sql = "select * from linkman where id=?";
  Contactor c = qr.query(sql, new BeanHandler<Contactor>(Contactor.class), id);
  return c;
 }
 
}
package cn.edu.aynu.rjxy.dao;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import cn.edu.aynu.rjxy.bean.User;
import cn.edu.aynu.rjxy.utils.JDBCUtils;

/**
 * 對user表的查詢
 * @author Administrator
 *
 */
public class UserDao {
 private QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());
 /**
  * 根據(jù)用戶名和用戶密碼查詢
  * @param cid
  * @return
  * @throws SQLException
  */
 public User findByCid(String username,String password) throws SQLException{
  String sql = "select * from user where username=?&&password=?";
  User u = qr.query(sql, new BeanHandler<User>(User.class), username,password);
  return u;
 }
 /**
  * 注冊
  * @param c
  * @throws SQLException 
  */
 public void register(User u) throws SQLException{
  String sql = "insert into user(username,password) values(?,?)";
  qr.update(sql, u.getUsername(),u.getPassword());
 }
}
package cn.edu.aynu.rjxy.service;

import java.sql.SQLException;
import java.util.List;

import cn.edu.aynu.rjxy.bean.Contactor;
import cn.edu.aynu.rjxy.dao.ContactorDao;

/**
 * 聯(lián)系人功能處理
 * @author Administrator
 *
 */
public class ContactorService {
 //創(chuàng)建ContactorDao對象
 ContactorDao dao = new ContactorDao();
 /**
  * 添加聯(lián)系人
  * @param c
  */
 public void add(Contactor c,int userId){
  try {
   dao.insert(c,userId);
  } catch (SQLException e) {
   throw new RuntimeException(e);
  }
 }
 /**
  * 刪除聯(lián)系人
  * @param cid
  */
 public void delete(int id){
  try {
   dao.delete(id);
  } catch (SQLException e) {
   throw new RuntimeException(e);
  }
 }
 /**
  * 加載(查詢)聯(lián)系人
  * @param cid
  */
 public List<Contactor> load(int userId){
  try {
   return dao.findAll(userId);
  } catch (SQLException e) {
   throw new RuntimeException(e);
  }
 }
 /**
  * 加載(查詢)聯(lián)系人(為修改做準備)
  * @param cid
  */
 public Contactor loadById(int id){
  try {
   return dao.findByCid(id);
  } catch (SQLException e) {
   throw new RuntimeException(e);
  }
 }
 /**
  * 編輯(修改)聯(lián)系人信息
  * @param c
  */
 public void edit(Contactor c,int userId){
  try {
   dao.update(c,userId);
  } catch (SQLException e) {
   throw new RuntimeException(e);
  }
 }
 
}
package cn.edu.aynu.rjxy.service;

import java.sql.SQLException;

import cn.edu.aynu.rjxy.bean.User;
import cn.edu.aynu.rjxy.dao.UserDao;


/**
 * 
 * @author Administrator
 *
 */
public class UserService {
 //創(chuàng)建ContactorDao對象
 UserDao dao = new UserDao();
 /**
  * 根據(jù)用戶名和密碼查詢用戶
  * @param cid
  */
 public User login(String username,String password){
  try {
   return dao.findByCid(username,password);
  } catch (SQLException e) {
   throw new RuntimeException(e);
  }
 }
 /**
  * 注冊
  * @param c
  */
 public void register(User u){
  try {
   dao.register(u);
  } catch (SQLException e) {
   throw new RuntimeException(e);
  }
 }
}
package cn.edu.aynu.rjxy.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.edu.aynu.rjxy.bean.Contactor;
import cn.edu.aynu.rjxy.bean.User;
import cn.edu.aynu.rjxy.service.ContactorService;
import cn.edu.aynu.rjxy.service.UserService;
import cn.edu.aynu.rjxy.utils.CommonsUtils;
/**
 * 處理聯(lián)系人請求
 * @author Administrator
 *
 */
public class ContactorServlet extends HttpServlet {
 private ContactorService cs = new ContactorService();
 private UserService us = new UserService();
 private int userId;
 public void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {

  this.doPost(request, response);
 }

 /**
  * 通過獲取表單中的隱藏字段method或者超鏈接中的method參數(shù)的值來區(qū)分調(diào)用執(zhí)行那個方法來處理這個請求
  */
 public void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  //處理中文亂碼
  request.setCharacterEncoding("UTF-8");
  response.setContentType("text/html;charset=UTF-8");
  //獲取隱藏字段method的值,并把它轉(zhuǎn)換為int型
  int method = Integer.parseInt(request.getParameter("method"));
  
  switch(method){
   case 1: this.register(request, response);
     break;
   case 2: this.login(request, response);
     break;
   case 3: this.query(request, response);
     break;
   case 4: this.add(request, response);
     break;
   case 5: this.loadForUpdate(request, response);
     break;
   case 6: this.edit(request, response);
     break;
   case 7: this.delete(request, response);
     break;
  }
  
  
 }
 /**
  * 處理注冊的請求
  * @param request
  * @param response
  * @throws ServletException
  * @throws IOException
  */
 public void register(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
  //使用CommonUtils工具類將請求數(shù)據(jù)封裝到bean中
  User u = CommonsUtils.toBean(request.getParameterMap(), User.class);
  //執(zhí)行添加客戶業(yè)務(wù)
  us.register(u);
  //輸出添加成功提示
  response.getWriter().print("注冊成功,三秒鐘自動跳轉(zhuǎn)到登錄界面");
  response.setHeader("Refresh","3;url=http://127.0.0.1:8099/addresslist/jsp/top.jsp"); 

 }
 /**
  * 處理登錄的請求 method=2
  * @param request
  * @param response
  * @throws ServletException
  * @throws IOException
  */
 public void login(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  //從請求中解析用戶名和密碼
  String username = request.getParameter("username");
  String password = request.getParameter("password");
  //執(zhí)行加載業(yè)務(wù)
  User u = us.login(username, password);
  if (u != null) {
   HttpSession session = request.getSession();
   session.setAttribute("userId", u.getId());
   response.getWriter().print("登錄成功"+u.getId());
   //通過請求轉(zhuǎn)發(fā)將pb帶到list.jsp上去
   request.getRequestDispatcher("/jsp/list.jsp").forward(request, response);
  }else{
   response.getWriter().print("登錄失敗,即將跳轉(zhuǎn)到登錄頁面,請重新登錄......");
   response.setHeader("Refresh","3;url=http://127.0.0.1:8099/addresslist/jsp/top.jsp"); 

  }
  
 }
 /**
  * 處理查看聯(lián)系人的請求 method=3
  * @param request
  * @param response
  * @throws ServletException
  * @throws IOException
  */
 public void query(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  HttpSession session = request.getSession();
   userId = (Integer) session.getAttribute("userId");
  //執(zhí)行查詢業(yè)務(wù)
  List<Contactor> list = cs.load(userId);
  //將list存放到request域中
  request.setAttribute("contactorList", list);
  System.out.println(list.size());
  //通過請求轉(zhuǎn)發(fā)將查詢結(jié)果帶到list.jsp頁面上顯示
  request.getRequestDispatcher("/jsp/list.jsp").forward(request, response);
  
 }
 /**
  * 處理添加客戶的請求
  * @param request
  * @param response
  * @throws ServletException
  * @throws IOException
  */
 public void add(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
  HttpSession session = request.getSession();
  userId = (Integer) session.getAttribute("userId");
  //使用CommonUtils工具類將請求數(shù)據(jù)封裝到bean中
  Contactor c = CommonsUtils.toBean(request.getParameterMap(), Contactor.class);
  //執(zhí)行添加客戶業(yè)務(wù)
  cs.add(c,userId);
  //輸出添加成功提示
  response.getWriter().print("添加成功,三秒后跳轉(zhuǎn)到功能界面......");
  response.setHeader("Refresh","3;url=http://127.0.0.1:8099/addresslist/jsp/list.jsp"); 
 }
 /**
  * 處理加載某一個客戶的請求
  * @param request
  * @param response
  * @throws ServletException
  * @throws IOException
  */
 public void loadForUpdate(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
  //從請求中獲取客戶的cid
  String ids = request.getParameter("id");
  int id = Integer.valueOf(ids);
  //執(zhí)行加載業(yè)務(wù)
  Contactor c = cs.loadById(id);
  //將Customer對象c保存在request域中
  request.setAttribute("contactor", c);
  //通過請求轉(zhuǎn)發(fā)將customer對象顯示在list.jsp頁面上
  request.getRequestDispatcher("/jsp/edit.jsp").forward(request, response);

 }
 /**
  * 處理更改某一聯(lián)系人的請求
  * @param request
  * @param response
  * @throws ServletException
  * @throws IOException
  */
 public void edit(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
  HttpSession session = request.getSession();
  userId = (Integer) session.getAttribute("userId");
  //使用CommonUtils工具類將請求數(shù)據(jù)封裝到bean中
  Contactor c = CommonsUtils.toBean(request.getParameterMap(), Contactor.class);
  //執(zhí)行更改業(yè)務(wù)
  cs.edit(c,userId);
  //給客戶端發(fā)送更改成功提示
  response.getWriter().print("更改成功,三秒后跳轉(zhuǎn)到功能界面......");
  response.setHeader("Refresh","3;url=http://127.0.0.1:8099/addresslist/jsp/list.jsp"); 

 }
 /**
  * 處理刪除某一聯(lián)系人的請求
  * @param request
  * @param response
  * @throws ServletException
  * @throws IOException
  */
 public void delete(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
  //從請求中獲取cid
  String cid = request.getParameter("id");
  int id = Integer.valueOf(cid);
  //執(zhí)行刪除客戶業(yè)務(wù)
  cs.delete(id);
  //給客戶端發(fā)送刪除成功提示
  response.getWriter().print("刪除成功,三秒后跳轉(zhuǎn)到功能界面......");
  response.setHeader("Refresh","3;url=http://127.0.0.1:8099/addresslist/jsp/list.jsp"); 


}

}
package cn.edu.aynu.rjxy.utils;

import java.util.Map;
import java.util.UUID;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;

/**
 * 提供UUID,實現(xiàn)表單數(shù)據(jù)封裝到bean中
 * @author Administrator
 *
 */
public class CommonsUtils {
 /**
  * 返回一個UUID
  * @return
  */
 public static String uuid(){
  return UUID.randomUUID().toString().replace("-", "").toUpperCase();
  
 }
 
 /**
  * 把表單數(shù)據(jù)封裝到bean中
  */
 public static <T> T toBean(Map data, Class<T> clazz){
  try{
   T bean = clazz.newInstance();
   BeanUtils.populate(bean, data);
   return bean;
  }catch (Exception e) {
   throw new RuntimeException(e);
  }
 }
 
 
}
package cn.edu.aynu.rjxy.utils;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

/**
 * 創(chuàng)建數(shù)據(jù)庫連接池
 * @author Administrator
 *
 */
public class JDBCUtils {
 //讀取的是C3P0-config默認配置創(chuàng)建數(shù)據(jù)庫連接池對象
 private static DataSource ds = new ComboPooledDataSource();
 //獲取數(shù)據(jù)庫連接池對象
 public static DataSource getDataSource(){
  return ds;
 }
 //從池中獲取連接
 public static Connection getConnection() throws SQLException{
  return ds.getConnection();
 } 
}
<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
 <!-- 默認配置,當使用ComboPooledDataSource無參構(gòu)造器時,使用的就是這個配置 -->
 <default-config>
  <!-- 基本配置 -->
  <property name="jdbcUrl">jdbc:mysql://localhost:3306/linkman?characterEncoding=UTF-8</property>
  <property name="driverClass">com.mysql.jdbc.Driver</property>
  <property name="user">root</property>
  <property name="password">123456</property>
  <!-- 每次增量,當需要創(chuàng)建Connection對象時,一次創(chuàng)建幾個 -->
  <property name="acquireIncrement">3</property>
  <!-- 當創(chuàng)建池對象后,池中應(yīng)該有幾個Connection對象 -->
  <property name="initialPoolSize">10</property>
  <!-- 池中最少Connection個數(shù),如果少于這個值,就會創(chuàng)建Connection -->
  <property name="minPoolSize">2</property>
  <!-- 池中最大連接個數(shù) -->
  <property name="maxPoolSize">10</property>
 </default-config>
</c3p0-config>

該工程需要的jar包:

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java實現(xiàn)多項式除法的代碼示例

    Java實現(xiàn)多項式除法的代碼示例

    今天小編就為大家分享一篇關(guān)于Java實現(xiàn)多項式除法的代碼示例,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-10-10
  • SpringBoot的reload加載器的方法

    SpringBoot的reload加載器的方法

    本篇文章主要介紹了SpringBoot的reload加載器的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • IntelliJ IDEA本地代碼覆蓋后恢復原來的代碼圖解

    IntelliJ IDEA本地代碼覆蓋后恢復原來的代碼圖解

    今天小編就為大家分享一篇關(guān)于IntelliJ IDEA本地代碼覆蓋后恢復原來的代碼圖解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-10-10
  • Java基礎(chǔ):徹底搞懂java多線程

    Java基礎(chǔ):徹底搞懂java多線程

    篇文章主要介紹了Java多線程的相關(guān)資料,幫助大家更好的理解和學習Java線程相關(guān)知識,感興趣的朋友可以了解下,希望能給你帶來幫助
    2021-08-08
  • Java如何判斷一個url是否有效

    Java如何判斷一個url是否有效

    URL類提供了一個openConnection()方法,可以打開一個連接并返回一個URLConnection對象,該對象可以用來檢查連接是否有效,這篇文章主要介紹了Java判斷一個url是否有效,需要的朋友可以參考下
    2023-09-09
  • Spring MVC+FastJson+Swagger集成的完整實例教程

    Spring MVC+FastJson+Swagger集成的完整實例教程

    這篇文章主要給大家分享介紹了關(guān)于Spring MVC+FastJson+Swagger集成的完整實例教程,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。
    2018-04-04
  • 一篇文章帶你入門Java運算符

    一篇文章帶你入門Java運算符

    這篇文章主要介紹了Java基本數(shù)據(jù)類型和運算符,結(jié)合實例形式詳細分析了java基本數(shù)據(jù)類型、數(shù)據(jù)類型轉(zhuǎn)換、算術(shù)運算符、邏輯運算符等相關(guān)原理與操作技巧,需要的朋友可以參考下
    2021-08-08
  • Java中生產(chǎn)者消費者問題總結(jié)

    Java中生產(chǎn)者消費者問題總結(jié)

    這篇文章主要介紹了Java中生產(chǎn)者消費者問題總結(jié),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-07-07
  • 在JAR文件中找不到主清單屬性的原因與解決方案

    在JAR文件中找不到主清單屬性的原因與解決方案

    在Java中,一個JAR文件通常包含一個名為MANIFEST.MF的清單文件,這個文件定義了關(guān)于JAR文件的各種元數(shù)據(jù),然而,有時我們可能會遇到一個問題,那就是在JAR文件中找不到主清單屬性,本文給大家介紹了JAR文件中找不到主清單屬性的原因和解決方案,需要的朋友可以參考下
    2024-04-04
  • Java集合之Set接口及其實現(xiàn)類精解

    Java集合之Set接口及其實現(xiàn)類精解

    set接口是繼承自Collection的子接口,特點是元素不重復,存儲無序。在set接口的實現(xiàn)類中添加重復元素是不會成功的,判斷兩個元素是否重復根據(jù)元素類重寫的
    2021-09-09

最新評論