反射工具类RelfectionUtils

 package Utils;

 import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type; /**
* 反射的 Utils 函数集合
* 提供访问私有变量, 获取泛型类型 Class, 提取集合中元素属性等 Utils 函数
* @author Administrator
*
*/
public class ReflectionUtils { /**
* 通过反射, 获得定义 Class 时声明的父类的泛型参数的类型
* 如: public EmployeeDao extends BaseDao<Employee, String>
* @param clazz
* @param index
* @return
*/
@SuppressWarnings("unchecked")
public static Class getSuperClassGenricType(Class clazz, int index){
Type genType = clazz.getGenericSuperclass(); if(!(genType instanceof ParameterizedType)){
return Object.class;
} Type [] params = ((ParameterizedType)genType).getActualTypeArguments(); if(index >= params.length || index < 0){
return Object.class;
} if(!(params[index] instanceof Class)){
return Object.class;
} return (Class) params[index];
} /**
* 通过反射, 获得 Class 定义中声明的父类的泛型参数类型
* 如: public EmployeeDao extends BaseDao<Employee, String>
* @param <T>
* @param clazz
* @return
*/
@SuppressWarnings("unchecked")
public static<T> Class<T> getSuperGenericType(Class clazz){
return getSuperClassGenricType(clazz, 0);
} /**
* 循环向上转型, 获取对象的 DeclaredMethod
* @param object
* @param methodName
* @param parameterTypes
* @return
*/
public static Method getDeclaredMethod(Object object, String methodName, Class<?>[] parameterTypes){ for(Class<?> superClass = object.getClass(); superClass != Object.class; superClass = superClass.getSuperclass()){
try {
//superClass.getMethod(methodName, parameterTypes);
return superClass.getDeclaredMethod(methodName, parameterTypes);
} catch (NoSuchMethodException e) {
//Method 不在当前类定义, 继续向上转型
}
//..
} return null;
} /**
* 使 filed 变为可访问
* @param field
*/
public static void makeAccessible(Field field){
if(!Modifier.isPublic(field.getModifiers())){
field.setAccessible(true);
}
} /**
* 循环向上转型, 获取对象的 DeclaredField
* @param object
* @param filedName
* @return
*/
public static Field getDeclaredField(Object object, String filedName){ for(Class<?> superClass = object.getClass(); superClass != Object.class; superClass = superClass.getSuperclass()){
try {
return superClass.getDeclaredField(filedName);
} catch (NoSuchFieldException e) {
//Field 不在当前类定义, 继续向上转型
}
}
return null;
} /**
* 直接调用对象方法, 而忽略修饰符(private, protected)
* @param object
* @param methodName
* @param parameterTypes
* @param parameters
* @return
* @throws InvocationTargetException
* @throws IllegalArgumentException
*/
public static Object invokeMethod(Object object, String methodName, Class<?> [] parameterTypes,
Object [] parameters) throws InvocationTargetException{ Method method = getDeclaredMethod(object, methodName, parameterTypes); if(method == null){
throw new IllegalArgumentException("Could not find method [" + methodName + "] on target [" + object + "]");
} method.setAccessible(true); try {
return method.invoke(object, parameters);
} catch(IllegalAccessException e) {
System.out.println("不可能抛出的异常");
} return null;
} /**
* 直接设置对象属性值, 忽略 private/protected 修饰符, 也不经过 setter
* @param object
* @param fieldName
* @param value
*/
public static void setFieldValue(Object object, String fieldName, Object value){
Field field = getDeclaredField(object, fieldName); if (field == null)
throw new IllegalArgumentException("Could not find field [" + fieldName + "] on target [" + object + "]"); makeAccessible(field); try {
field.set(object, value);
} catch (IllegalAccessException e) {
System.out.println("不可能抛出的异常");
}
} /**
* 直接读取对象的属性值, 忽略 private/protected 修饰符, 也不经过 getter
* @param object
* @param fieldName
* @return
*/
public static Object getFieldValue(Object object, String fieldName){
Field field = getDeclaredField(object, fieldName); if (field == null)
throw new IllegalArgumentException("Could not find field [" + fieldName + "] on target [" + object + "]"); makeAccessible(field); Object result = null; try {
result = field.get(object);
} catch (IllegalAccessException e) {
System.out.println("不可能抛出的异常");
} return result;
}
}

jdbcutils

 package Utils;

 import java.sql.Connection;
import java.sql.SQLException; import javax.sql.DataSource; import com.mchange.v2.c3p0.ComboPooledDataSource; public class JdbcUtil { public static void reaseConnection(Connection connection) {
try {
if(connection!=null){
connection.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static DataSource dataSource = null;
static{
dataSource = new ComboPooledDataSource("mvc");
} public static DataSource getDataSource(){
return dataSource;
} public static Connection getConnection(){
try {
return dataSource.getConnection();
} catch (SQLException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
System.out.println("连接失败");
}
return null; }
}

DAO操作类 依靠c3p0,dbutil

 package com.mvc.dao;

 import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.sql.Connection;
import java.sql.PreparedStatement;
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 org.apache.el.util.ReflectionUtil; import com.sun.org.apache.bcel.internal.generic.NEW; import Utils.JdbcUtil;
import Utils.ReflectionUtils; public class Dao<T> {
private Class<T> clazz;
private QueryRunner queryRunner= new QueryRunner(JdbcUtil.getDataSource());
public Dao() {
clazz = ReflectionUtils.getSuperGenericType(this.getClass());
}
public <E> E getForValue(String sql,Object ...arg){
try {
return (E) queryRunner.query(sql,new ScalarHandler(),arg);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("getForValue error");
}
return null; }
public List<T> getForList(String sql,Object ...args){
try {
return queryRunner.query(sql, new BeanListHandler<>(clazz),args);
} catch (SQLException e) {
System.out.println("getForList error");
}
return null; }
public T get(String sql,Object ...args){
try {
return queryRunner.query(sql,new BeanHandler<>(clazz),args);
} catch (SQLException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
System.out.println("get error");
}
return null;
} public void updata(String sql,Object ...args){
try {
queryRunner.update(sql,args);
} catch (SQLException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
System.out.println("updata error");
}
}
}

Customer类

package com.mvc.domain;

public class Customer {
private String id;
private String name;
private String address;
private String phone;
private int count; public Customer() {
super();
}
public Customer(String id, String name, String address, String phone) {
super();
this.id = id;
this.name = name;
this.address = address;
this.phone = phone;
this.count = 0;
} public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
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 getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
@Override
public String toString() {
return "Customer [id=" + id + ", name=" + name + ", address=" + address + ", phone=" + phone + "]";
} }

CustomerDao接口

 package com.mvc.dao;

 import java.util.List;

 import com.mvc.domain.CriteriaCustomer;
import com.mvc.domain.Customer; public interface CustomerDao {
public List<Customer> getAll();
public void save(Customer customer);
public void upCount(Customer customer);
public void upAll(Customer customer);
public Customer getForIdName(String id,String name);
public Customer getForId(String id);
public void delete(String id);
public long getCountWithName(String name);
public long getCountWithId(String id);
public List<Customer> getCriteriaCustomers(CriteriaCustomer cc);
}

操作类

 package com.mvc.jdbc;

 import java.sql.SQLException;
import java.util.List; import com.mvc.dao.CustomerDao;
import com.mvc.dao.Dao;
import com.mvc.domain.CriteriaCustomer;
import com.mvc.domain.Customer; public class CustomerDaoJdbc extends Dao<Customer> implements CustomerDao{ @Override
public List<Customer> getAll(){
// TODO Auto-generated method stub
String sql = "SELECT * FROM customer";
return getForList(sql);
} @Override
public void save(Customer customer) {
// TODO Auto-generated method stub
String sql = "insert into customer(id,name,address,phone,count) value(?,?,?,?,?)";
updata(sql,customer.getId(),customer.getName(),customer.getAddress(),customer.getPhone(),customer.getCount()); } @Override
public void upAll(Customer customer) {
// TODO Auto-generated method stub
String sql = "UPDATE customer SET NAME=?,ADDRESS=?,PHONE=? WHERE ID=?";
updata(sql,customer.getName(),customer.getAddress(),customer.getPhone(),customer.getId()); } @Override
public void upCount(Customer customer) {
// TODO Auto-generated method stub
String sql = "UPDATE customer SET COUNT=? WHERE ID=?";
updata(sql,customer.getCount(),customer.getId());
} @Override
public Customer getForIdName(String id,String name) {
// TODO Auto-generated method stub
String sql = "SELECT id,name,address,phone,count FROM customer where id = ? and name = ?";
return get(sql,id,name);
}
@Override
public Customer getForId(String id) {
// TODO Auto-generated method stub
String sql = "SELECT id,name,address,phone,count FROM customer where id = ?";
return get(sql,id);
}
@Override
public void delete(String id) {
// TODO Auto-generated method stub
String sql = "delete from customer where ID = ? ";
updata(sql,id); } @Override
public long getCountWithName(String name) {
// TODO Auto-generated method stub
String sql = "select count(id) from customer where name = ?";
return (long)getForValue(sql, name);
} @Override
public List<Customer> getCriteriaCustomers(CriteriaCustomer cc) {
// TODO Auto-generated method stub
String sql = "SELECT * FROM customer WHERE NAME LIKE ? AND address LIKE ? AND phone LIKE ?";
System.out.println(cc.getName()+cc.getAddress()+cc.getPhone());
return getForList(sql,cc.getName(),cc.getAddress(),cc.getPhone());
} @Override
public long getCountWithId(String id) {
// TODO Auto-generated method stub
String sql = "select count(id) from customer where id= ?";
return (long)getForValue(sql, id);
} }

servlet

 package com.mvc.servlet;

 import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List; import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.mvc.dao.CustomerDao;
import com.mvc.domain.CriteriaCustomer;
import com.mvc.domain.Customer;
import com.mvc.jdbc.CustomerDaoJdbc;
import com.sun.corba.se.impl.protocol.giopmsgheaders.Message; import jdk.nashorn.internal.ir.RuntimeNode.Request; /**
* Servlet implementation class SqlServlet
*/
@WebServlet("/SqlServlet")
public class SqlServlet extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
CustomerDao customerDao = null; public SqlServlet() {
super();
// TODO Auto-generated constructor stub
customerDao = new CustomerDaoJdbc();
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("utf-8");
String servletPath = request.getServletPath();
// System.out.println(servletPath);
servletPath = servletPath.substring(1, servletPath.length() - 3);
try {
Method method = getClass().getDeclaredMethod(servletPath,
HttpServletRequest.class, HttpServletResponse.class);
method.invoke(this, request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } @SuppressWarnings("unused")
private void edit(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("edit");
String id = request.getParameter("id");
System.out.println(id);
Customer customer = customerDao.getForId(id);
System.out.println(customer);
request.setAttribute("customer", customer);
request.getRequestDispatcher("/updata.jsp").forward(request, response);
} @SuppressWarnings("unused")
private void updata(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("updata");
String id = request.getParameter("id");
String name = request.getParameter("name");
String address = request.getParameter("address");
String phone = request.getParameter("phone");
Customer customer = new Customer(id, name, address, phone);
String massage;
massage = "修改成功";
customerDao.upAll(customer);
request.setAttribute("massage", massage);
request.setAttribute("customer", customer);
request.getRequestDispatcher("/updata.jsp").forward(request, response); } @SuppressWarnings("unused")
private void add(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("add");
String id = request.getParameter("id");
String name = request.getParameter("name");
String address = request.getParameter("address");
String phone = request.getParameter("phone");
Customer customer = new Customer(id, name, address, phone);
System.out.println(customer);
long count = customerDao.getCountWithName(name);
long count1 = customerDao.getCountWithId(id);
System.out.println("count:" + count);
request.setAttribute("id", id);
request.setAttribute("name", name);
request.setAttribute("address", address);
request.setAttribute("phone", phone);
if (count1 > 0) {
request.setAttribute("massage", "学号已存在,报名失败");
request.getRequestDispatcher("/newcustomer.jsp").forward(request,
response);
} else {
request.setAttribute("massage", "报名成功");
customerDao.save(customer);
request.getRequestDispatcher("/newcustomer.jsp").forward(request,
response);
}
} @SuppressWarnings("unused")
private void delete(HttpServletRequest request, HttpServletResponse response)
throws IOException {
System.out.println("delete");
String id = request.getParameter("id");
System.out.println(id);
//customerDao.delete(id); //response.sendRedirect("query.do");
} @SuppressWarnings("unused")
private void query(HttpServletRequest request, HttpServletResponse response) {
String name = request.getParameter("name");
String address = request.getParameter("address");
String phone = request.getParameter("phone");
System.out.println(name + address + phone);
System.out.println("query");
CriteriaCustomer cc = new CriteriaCustomer(name, address, phone);
List<Customer> customers = customerDao.getCriteriaCustomers(cc);
request.setAttribute("customers", customers);
try {
request.getRequestDispatcher("/1.jsp").forward(request,
response);
} catch (ServletException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} @SuppressWarnings("unused")
private void come(HttpServletRequest request, HttpServletResponse response) {
String name = request.getParameter("name");
String id = request.getParameter("id");
Customer customer = customerDao.getForIdName(id, name);
System.out.println(customer);
if (customer != null) {
request.setAttribute("massage", "");
customer.setCount(customer.getCount() + 1);
customerDao.upCount(customer);
//response.sendRedirect("NewFile_1.jsp");
try {
request.getRequestDispatcher("/NewFile_1.jsp").forward(request,
response);
} catch (ServletException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } else {
try {
String massage = "名字或学号错误";
request.setAttribute("massage", massage);
request.setAttribute("id", id);
request.setAttribute("name", name);
request.getRequestDispatcher("/come.jsp").forward(request,
response);
} catch (ServletException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

以下jsp代码 css样式等为网上找的素材

1.增加用户的jsp

 <%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--[if IE]><meta http-equiv="x-ua-compatible" content="IE=9" /><![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Your Description Here">
<meta name="keywords"
content="bootstrap themes, portfolio, responsive theme">
<meta name="author" content="ThemeForces.Com"> <!-- Favicons
================================================== -->
<!-- <link rel="shortcut-icon" href="img/favicon.ico" type="image/x-icon"> -->
<!-- <link rel="apple-touch-icon" href="img/apple-touch-icon.png"> -->
<link rel="apple-touch-icon" sizes="72x72"
href="img/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114"
href="img/apple-touch-icon-114x114.png"> <!-- Bootstrap -->
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<!-- <link rel="stylesheet" type="text/css"
href="fonts/font-awesome/css/font-awesome.css"> --> <!-- Stylesheet
================================================== -->
<link rel="stylesheet" type="text/css" href="css/style.css">
<!-- <link rel="stylesheet" type="text/css" href="css/responsive.css"> --> <!-- <script type="text/javascript" src="js/modernizr.custom.js"></script> --> <title></title>
</head>
<body>
<h3 style="text-align: center;"><font color="red"><c:out value="${massage}"></c:out></font></h3>
<div id="tf-contact">
<div class="container">
<div class="section-title">
<hr>
</div> <div class="space"></div> <div class="row">
<div class="col-md-6 col-md-offset-3">
<form id="contact" action="add.do" method="post">
<div class="form-group">
<input class="form-control" id="exampleInputEmail1" type="text"
name="id" value="${id}" placeholder="长学号" />
</div> <div class="form-group">
<input class="form-control" type="text" name="name"
value="${name}" placeholder="姓名" />
</div> <div class="form-group">
<input class="form-control" type="text" name="address"
value="${address}" placeholder="班级" />
</div> <td><div class="form-group">
<input class="form-control" type="text" name="phone"
value="${phone}" placeholder="手机" />
</div>
<input class="btn btn-primary my-btn dark" type="submit"
value="--报名--" />
</form>
</div>
</div>
</div>
</div>
<!-- <script type="text/javascript" src="js/jquery.1.11.1.js"></script>-->
<!-- Include all compiled plugins (below), or include individual files as needed -->
<!-- <script type="text/javascript" src="js/bootstrap.js"></script> --> <!-- Javascripts
================================================== -->
<!-- <script type="text/javascript" src="js/main.js"></script>-->
</body>
</html>

2.查询

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="scripts/jquery-1.7.2.js"></script>
<script type="text/javascript">
</script>
</head>
<body> <form action="query.do" method="post">
<table>
<tr>
<td>CustomerName:</td>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address"/></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text" name="phone"/></td>
</tr>
<tr>
<td><input type="submit" value="Query"/></td>
<td><a href="newcustomer.jsp">Add New Customer</a></td>
</tr>
</table>
</form> <br><br> <c:if test="${!empty requestScope.customers }"> <hr>
<br><br> <table border="1" cellpadding="10" cellspacing="0">
<tr>
<th>^ID</th>
<th>CustomerName</th>
<th>Address</th>
<th>Phone</th>
<th>UPDATE\DELETE</th>
</tr> <c:forEach items="${requestScope.customers }" var="cust"> <tr>
<td>${cust.id }</td>
<td>${cust.name }</td>
<td>${cust.address }</td>
<td>${cust.phone }</td>
<td>
<c:url value="/edit.do" var="editurl">
<c:param name="id" value="${cust.id }"></c:param>
</c:url>
<a href="${editurl }">UPDATE</a>
<c:url value="/delete.do" var="deleteurl">
<c:param name="id" value="${cust.id }"></c:param>
</c:url>
<a href="${deleteurl }" class="delete">DELETE</a>
</td>
</tr> </c:forEach> </table>
</c:if> </body>
</html>

3.删除

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="scripts/jquery-1.7.2.js"></script> </head>
<body> <form action="query.do" method="post">
<table>
<tr>
<td>CustomerName:</td>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address"/></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text" name="phone"/></td>
</tr>
<tr>
<td><input type="submit" value="Query"/></td>
<td><a href="newcustomer.jsp">Add New Customer</a></td>
</tr>
</table>
</form> <br><br> <c:if test="${!empty requestScope.customers }"> <hr>
<br><br> <table border="1" cellpadding="10" cellspacing="0">
<tr>
<th>^ID</th>
<th>CustomerName</th>
<th>Address</th>
<th>Phone</th>
<th>UPDATE\DELETE</th>
</tr> <c:forEach items="${requestScope.customers }" var="cust"> <tr>
<td>${cust.id }</td>
<td>${cust.name }</td>
<td>${cust.address }</td>
<td>${cust.phone }</td>
<td>
<c:url value="/edit.do" var="editurl">
<c:param name="id" value="${cust.id }"></c:param>
</c:url>
<a href="${editurl }">UPDATE</a>
<c:url value="/delete.do" var="deleteurl">
<c:param name="id" value="${cust.id }"></c:param>
</c:url>
<a href="${deleteurl }" class="delete">DELETE</a>
</td>
</tr> </c:forEach> </table>
</c:if> </body>
</html>

4.修改

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--[if IE]><meta http-equiv="x-ua-compatible" content="IE=9" /><![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Your Description Here">
<meta name="keywords"
content="bootstrap themes, portfolio, responsive theme">
<meta name="author" content="ThemeForces.Com"> <!-- Favicons
================================================== -->
<link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon">
<link rel="apple-touch-icon" href="img/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72"
href="img/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114"
href="img/apple-touch-icon-114x114.png"> <!-- Bootstrap -->
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css"
href="fonts/font-awesome/css/font-awesome.css"> <!-- Stylesheet
================================================== -->
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/responsive.css"> <script type="text/javascript" src="js/modernizr.custom.js"></script> <title></title>
</head>
<body> <c:if test="${requestScope.massage != null }">
<br>
<h3 style="text-align: center;"><font color="red"><c:out value="${massage}"></c:out></font></h3>
<br>
<br>
</c:if> <c:set var="id" value="${customer != null ? customer.id : param.id }"></c:set> <c:set var="name"
value="${customer != null ? customer.name : param.name }"></c:set>
<c:set var="address"
value="${customer != null ? customer.address : param.address }"></c:set>
<c:set var="phone"
value="${customer != null ? customer.phone : param.phone }"></c:set>
<div id="tf-contact">
<div class="container">
<div class="section-title"> <hr>
</div> <div class="space"></div> <div class="row">
<div class="col-md-6 col-md-offset-3">
<form id="contact" action="updata.do" method="post">
<input type="hidden" name="id" value="${id }"></input>
<div class="form-group">
<h4>姓名:</h4>
<input class="form-control" type="text" name="name"
value="${name}" placeholder="姓名" />
</div> <div class="form-group">
<h4>班级:</h4>
<input class="form-control" type="text" name="address"
value="${address}" placeholder="班级" />
</div> <div class="form-group">
<h4>手机:</h4>
<input class="form-control" type="text" name="phone"
value="${phone}" placeholder="手机" />
</div> <input class="btn btn-primary my-btn dark" type="submit"
value="修改" />
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="js/jquery.1.11.1.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script type="text/javascript" src="js/bootstrap.js"></script> <!-- Javascripts
================================================== -->
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>MVC</display-name> <servlet>
<description></description>
<display-name>SqlServlet</display-name>
<servlet-name>SqlServlet</servlet-name>
<servlet-class>com.mvc.servlet.SqlServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SqlServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping> </web-app>

运行效果 增加信息

数据库内数据

简单MVC实现增删改查的更多相关文章

  1. salesforce 零基础开发入门学习(六)简单的数据增删改查页面的构建

    VisualForce封装了很多的标签用来进行页面设计,本篇主要讲述简单的页面增删改查.使用的内容和设计到前台页面使用的标签相对简单,如果需要深入了解VF相关知识以及标签, 可以通过以下链接查看或下载 ...

  2. 分享一个自己写的MVC+EF “增删改查” 无刷新分页程序

    分享一个自己写的MVC+EF “增删改查” 无刷新分页程序 一.项目之前得添加几个组件artDialog.MVCPager.kindeditor-4.0.先上几个效果图.      1.首先建立一个数 ...

  3. 【ASP.NET MVC系列】浅谈jqGrid 在ASP.NET MVC中增删改查

    ASP.NET MVC系列文章 [01]浅谈Google Chrome浏览器(理论篇) [02]浅谈Google Chrome浏览器(操作篇)(上) [03]浅谈Google Chrome浏览器(操作 ...

  4. 【Mybatis】简单的mybatis增删改查模板

    简单的mybatis增删改查模板: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE map ...

  5. 【转载】salesforce 零基础开发入门学习(六)简单的数据增删改查页面的构建

    salesforce 零基础开发入门学习(六)简单的数据增删改查页面的构建   VisualForce封装了很多的标签用来进行页面设计,本篇主要讲述简单的页面增删改查.使用的内容和设计到前台页面使用的 ...

  6. 最简单的mybatis增删改查样例

    最简单的mybatis增删改查样例 Book.java package com.bookstore.app; import java.io.Serializable; public class Boo ...

  7. ASP.NET Identity系列02,在ASP.NET MVC中增删改查用户

    本篇体验在ASP.NET MVC中使用ASP.NET Identity增删改查用户. 源码在这里:https://github.com/darrenji/UseIdentityCRUDUserInMV ...

  8. MVC——数据库增删改查(aspx)

    MVC: V(View) :视图→就是页面的模板 C(Control): 控制器→客户主要面对的就是控制器, M(Model):模板→在模板里面主要就是写关于数据库的各种增删改查的方法 它们之间的关系 ...

  9. SQL简单语句(增删改查)

    简单的SQL语句增删改查操作 说明: 在mysql里面亲测结果正确    用到的表(学生表:studnets) 1.创建一个学生表,(学号,姓名,性别,家庭住址) mysql> create t ...

随机推荐

  1. 如何利用git由本机向github上传文件 ssh方式的

    1.直接在git bash里操作,输入命令cd ~/.ssh ls 2.如果不是这样的,说明没有生产公匙,然后输入命令 ssh-keygen -t rsa -C "自己的邮箱地址" ...

  2. php ActiveMQ的安装与使用

    一.ActiveMQ是什么?ActiveMQ是Apache出品,最流行的,能力强劲的开源消息总线.支持多种语言客户端(Java,C,C++,C#,Python,Ruby,Perl,PHP), 支持多种 ...

  3. C语言 内存

    内存属性: 1.大小 2.位置 int a;  默认方式  (段) 内核空间        应用程序不许访问 ------------------------------------------3g ...

  4. JavaScript 字符串用于存储和处理文本

    JavaScript 字符串用于存储和处理文本 var string_value='dasfsdfsd'; 注意:字符串利用索引精确定位取值 var character=string_value[7] ...

  5. Service Broker 概述

    ServiceBroker(简称SSB)是基于数据库引擎提供的一个强大的异步编程模型,通过ServiceBroker,开发人员无需编写复杂的通信和消息程序,即可在数据库实例之间完成高效可靠的异步通信. ...

  6. 详解php多人开发环境原理

    作为一名php开发人员,有时候一个项目或一个功能我们不能独自完成,就像当一个仓库开发人员大于1,20人的时候,每个人可能开发不同的模块和功能,用代码版本控制工具比如 git 开不同的分支,流程大概是先 ...

  7. String类为什么设计成不可变的

    在Java中将String设计成不可变的是综合考虑到各种因素的结果,需要综合考虑内存.同步.数据结构以安全方面的考虑. String被设计成不可变的主要目的是为了安全和高效. 1)字符串常量池的需要 ...

  8. Notepad++语言格式设置,自定义扩展名关联文件格式

    简单粗暴--直接上图

  9. 【Linux】OpenSSL 安装

    OpenSSL 简介 OpenSSL 是一个安全套接字层密码库,囊括主要的密码算法.常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用. OpenSSL 安装 环境:L ...

  10. 【Linux】zlib安装

    zlib简介 zlib是提供数据压缩用的函式库,由Jean-loup Gailly与Mark Adler所开发,初版0.9版在1995年5月1日发表.zlib使用DEFLATE算法,最初是为libpn ...