项目分析
由界面可以得知,需要完成登录、用户的增删改查操作
使用的技术
JSP+Servlet+Mybatis------>MVC
代码展示
配置文件和util工具类
mybatis.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<package name="com.bjsxt.entity"></package>
</typeAliases>
<environments default="mysql">
<environment id="mysql">
<transactionManager type="JDBC"></transactionManager>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/test"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</dataSource>
</environment>
</environments>
<mappers>
<package name="com.bjsxt.mapper"></package>
</mappers>
</configuration>
log4j.properties
log4j.rootCategory=error, CONSOLE,LOGFILE
#log4j.logger.com.bjsxt.mapper=debug
#log4j.logger.com.bjsxt.mapper.DeptMapper=debug
log4j.logger.com.bjsxt.mapper=debug
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=d:/axis.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
DBUtil.java
package com.bjsxt.util;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.IOException;
import java.io.InputStream;
public class DBUtil {
private static SqlSessionFactory sessionFactory;
private static ThreadLocal<SqlSession> tl =new ThreadLocal<>();
static {
try {
InputStream inputStream = Resources.getResourceAsStream("mybatis.xml");
sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
}
public static SqlSession getSession(){
SqlSession sqlSession = tl.get();
if(sqlSession==null){
sqlSession=sessionFactory.openSession(true);
tl.set(sqlSession);
}
return tl.get();
}
public static void closeAll(){
SqlSession sqlSession = tl.get();
if(sqlSession!=null){
sqlSession.close();
}
tl.set(null);
}
}
实体类----entity包
User.java
package com.bjsxt.entity;
import java.util.Date;
public class User {
private Integer id;
private String uname;
private String pwd;
private String sex;
private String hobby;
private Date birth;
private String phone;
private String remark;
public User() {
}
public User(Integer id, String uname, String pwd, String sex, String hobby, Date birth, String phone, String remark) {
this.id = id;
this.uname = uname;
this.pwd = pwd;
this.sex = sex;
this.hobby = hobby;
this.birth = birth;
this.phone = phone;
this.remark = remark;
}
public User( String uname, String pwd, String sex, String hobby, Date birth, String phone, String remark) {
this.uname = uname;
this.pwd = pwd;
this.sex = sex;
this.hobby = hobby;
this.birth = birth;
this.phone = phone;
this.remark = remark;
}
public User(String uname, String pwd) {
this.uname = uname;
this.pwd = pwd;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getHobby() {
return hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", uname='" + uname + '\'' +
", pwd='" + pwd + '\'' +
", sex='" + sex + '\'' +
", hobby='" + hobby + '\'' +
", birth=" + birth +
", phone='" + phone + '\'' +
", remark='" + remark + '\'' +
'}';
}
}
mapper层
UserMapper.java
package com.bjsxt.mapper;
import com.bjsxt.entity.User;
import java.util.List;
public interface UserMapper {
public User selectOne(String uname,String pwd);
public int save(User user);
public List<User> findAll();
public int delete(int id);
public User selectOne2(int id);
public int update(User user);
}
UserMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bjsxt.mapper.UserMapper">
<select id="selectOne" resultType="user">
select * from user where uname=#{0} and pwd=#{1}
</select>
<insert id="save">
insert into user values(default,#{uname},#{pwd},#{sex},#{hobby},#{birth},#{phone},#{remark})
</insert>
<select id="findAll" resultType="user">
select * from user
</select>
<delete id="delete">
delete from user where id=#{0}
</delete>
<select id="selectOne2" resultType="user">
select * from user where id=#{0}
</select>
<update id="update">
update user set uname=#{uname},pwd=#{pwd},sex=#{sex},hobby=#{hobby},birth=#{birth},phone=#{phone},remark=#{remark} where id=#{id}
</update>
</mapper>
业务层----service包
UserService.java
package com.bjsxt.service;
import com.bjsxt.entity.User;
import java.util.List;
public interface UserService {
public User selectOne(String uname,String pwd);
public int save(User user);
public List<User> findAll();
public int delete(int id);
public User findOne(int id);
public int change(User user);
}
UserServiceImpl.java
package com.bjsxt.service.Impl;
import com.bjsxt.entity.User;
import com.bjsxt.mapper.UserMapper;
import com.bjsxt.service.UserService;
import com.bjsxt.util.DBUtil;
import java.util.List;
public class UserServiceImpl implements UserService {
@Override
public User selectOne(String uname, String pwd) {
UserMapper mapper = DBUtil.getSession().getMapper(UserMapper.class);
User user = mapper.selectOne(uname, pwd);
DBUtil.closeAll();
return user;
}
@Override
public int save(User user) {
UserMapper mapper = DBUtil.getSession().getMapper(UserMapper.class);
int i = mapper.save(user);
DBUtil.closeAll();
return i;
}
@Override
public List<User> findAll() {
UserMapper mapper = DBUtil.getSession().getMapper(UserMapper.class);
List<User> list = mapper.findAll();
DBUtil.closeAll();
return list;
}
@Override
public int delete(int id) {
UserMapper mapper = DBUtil.getSession().getMapper(UserMapper.class);
int delete = mapper.delete(id);
DBUtil.closeAll();
return delete;
}
@Override
public User findOne(int id) {
UserMapper mapper = DBUtil.getSession().getMapper(UserMapper.class);
User user = mapper.selectOne2(id);
DBUtil.closeAll();
return user;
}
@Override
public int change(User user) {
UserMapper mapper = DBUtil.getSession().getMapper(UserMapper.class);
int change = mapper.update(user);
return change;
}
}
控制层----controller包
经过整合后,只有UserServlet.java有效
UserServlet.java
package com.bjsxt.controller;
import com.bjsxt.entity.User;
import com.bjsxt.service.Impl.UserServiceImpl;
import com.bjsxt.service.UserService;
import javax.servlet.ServletContext;
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 javax.servlet.http.Part;
import java.io.IOException;
import java.sql.Date;
import java.util.Arrays;
import java.util.List;
@WebServlet(urlPatterns = "/servlet/UserServlet")
public class UserServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String method = req.getParameter("method");
System.out.println("method:"+method);
if ("userLogin".equals(method)) {
userLogin(req,resp);
} else if ("userLoginOut".equals(method)) {
userLoginOut(req,resp);
} else if ("userSave".equals(method)) {
userSave(req,resp);
} else if ("userFindAll".equals(method)) {
userFindAll(req,resp);
} else if ("userFindOne".equals(method)) {
userFindOne(req,resp);
} else if ("userDelete".equals(method)) {
userDelete(req,resp);
} else if ("userChange".equals(method)) {
userChange(req,resp);
}
}
protected void userLogin(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String uname = req.getParameter("uname");
String pwd = req.getParameter("pwd");
UserService userService = new UserServiceImpl();
User user = userService.selectOne(uname, pwd);
if (user != null) {
//使用session完成欢迎xxx登录
req.getSession().setAttribute("uname",uname);
//访问人数
ServletContext context = req.getServletContext();
Integer count = (Integer) context.getAttribute("context");
if (count == null) {
count = 1;
} else {
count++;
}
context.setAttribute("context",count);
resp.sendRedirect(req.getContextPath() + "/index.jsp");
} else {
req.setAttribute("msg","登录失败");
req.getRequestDispatcher("/login.jsp").forward(req,resp);
}
}
protected void userLoginOut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.getSession().invalidate();
resp.sendRedirect(req.getContextPath()+"/login.jsp");
}
protected void userSave(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String unmae = req.getParameter("uname");
String pwd = req.getParameter("pwd");
String sex = req.getParameter("sex");
String hobby = Arrays.toString(req.getParameterValues("hobby"));
Date birth = Date.valueOf(req.getParameter("birth"));
String phone = req.getParameter("phone");
String remark = req.getParameter("remark");
User user = new User(unmae, pwd, sex, hobby, birth, phone, remark);
UserService userService = new UserServiceImpl();
int i = userService.save(user);
if (i > 0) {
// resp.sendRedirect(req.getContextPath()+"/servelt/UserServlet?method=userFindAll");
userFindAll(req,resp);
} else {
req.getRequestDispatcher("/saveUser.jsp").forward(req,resp);
}
}
protected void userFindAll(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
UserService userService = new UserServiceImpl();
List<User> user = userService.findAll();
/*if (user != null) {*/
req.setAttribute("user",user);
req.getRequestDispatcher("/listUser.jsp").forward(req,resp);
/*} else {
req.getRequestDispatcher("/listUser.jsp").forward(req,resp);
}*/
}
protected void userFindOne(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
int id = Integer.parseInt(req.getParameter("id"));
// System.out.println(id);
UserService userService = new UserServiceImpl();
User user = userService.findOne(id);
req.setAttribute("user",user);//user
req.getRequestDispatcher("/updateUser.jsp").forward(req,resp);
}
protected void userDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Integer id = Integer.parseInt(req.getParameter("id"));
UserService userService = new UserServiceImpl();
int delete = userService.delete(id);
resp.sendRedirect(req.getContextPath() + "/servlet/UserServlet?method=userFindAll");
}
protected void userChange(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String unmae = req.getParameter("uname");
String pwd = req.getParameter("pwd");
String sex = req.getParameter("sex");
String hobby = Arrays.toString(req.getParameterValues("hobby"));
Date birth = Date.valueOf(req.getParameter("birth"));
String phone = req.getParameter("phone");
String remark = req.getParameter("remark");
Integer id = Integer.parseInt(req.getParameter("id"));
User user = new User(id, unmae, pwd, sex, hobby, birth, phone, remark);
UserService userService = new UserServiceImpl();
int change = userService.change(user);
if (change > 0) {
resp.sendRedirect(req.getContextPath() + "/servlet/UserServlet?method=userFindAll");
} else {
req.setAttribute("msg","修改失败");
req.getRequestDispatcher("/updateUser.jsp").forward(req,resp);
}
}
}
web项目下的文件
login.jsp----登录页面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title>登录</title>
<base href="<%=request.getContextPath()+"/"%>">
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
</head>
<body>
<div class="bg"></div>
<div class="container">
<div class="line bouncein">
<div class="xs6 xm4 xs3-move xm4-move">
<div style="height:150px;"></div>
<div class="media media-y margin-big-bottom">
</div>
<form action="servlet/UserServlet?method=userLogin" method="post">
<div class="panel loginbox">
<div class="text-center margin-big padding-big-top"><h1>后台管理中心</h1></div>
<div class="panel-body" style="padding:30px; padding-bottom:10px; padding-top:10px;">
<div class="form-group">
<div class="field field-icon-right">
<input type="text" class="input input-big" name="uname" placeholder="登录账号" data-validate="required:请填写账号" />${msg}
<span class="icon icon-user margin-small"></span>
</div>
</div>
<div class="form-group">
<div class="field field-icon-right">
<input type="password" class="input input-big" name="pwd" placeholder="登录密码" data-validate="required:请填写密码" />
<span class="icon icon-key margin-small"></span>
</div>
</div>
<div class="form-group">
<div class="field">
<input type="text" class="input input-big" name="code" placeholder="填写右侧的验证码" data-validate="required:请填写右侧的验证码" />
<img src="images/passcode.jpg" alt="" width="100" height="32" class="passcode" style="height:43px;cursor:pointer;" onclick="this.src=this.src+'?'">
</div>
</div>
</div>
<div style="padding:30px;"><input type="submit" class="button button-block bg-main text-big input-big" value="登录"></div>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
index.jsp----主页面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title>后台管理中心</title>
<base href="<%=request.getContextPath()+"/"%>">
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
</head>
<body style="background-color:#f2f9fd;">
<div class="header bg-main">
<div class="logo margin-big-left fadein-top">
<h1><img src="images/y.jpg" class="radius-circle rotate-hover" height="50" alt="" />后台管理中心</h1>
</div>
<div style="float:right;margin-top: 40px;margin-right: 60px">
<h3>欢迎${sessionScope.uname}登录|<a href="servelt/UserServlet?method=userLoginOut">注销</a>|您是第[${applicationScope.context}]位访问客户</h3>
</div>
</div>
<div class="leftnav">
<div class="leftnav-title"><strong><span class="icon-list"></span>菜单列表</strong></div>
<h2><span class="icon-user"></span>用户管理</h2>
<ul style="display:block">
<li><a href="saveUser.jsp" target="right"><span class="icon-caret-right"></span>添加用户</a></li>
<li><a href="servlet/UserServlet?method=userFindAll" target="right"><span class="icon-caret-right"></span>展示用户</a></li>
</ul>
</div>
<script type="text/javascript">
$(function(){
$(".leftnav h2").click(function(){
$(this).next().slideToggle(200);
$(this).toggleClass("on");
})
$(".leftnav ul li a").click(function(){
$("#a_leader_txt").text($(this).text());
$(".leftnav ul li a").removeClass("on");
$(this).addClass("on");
})
});
</script>
<ul class="bread">
<li><a href="{:U('Index/info')}" target="right" class="icon-home"> 首页</a></li>
<li><a href="##" id="a_leader_txt">网站信息</a></li>
<li><b>当前语言:</b><span style="color:red;">中文</php></span>
切换语言:<a href="##">中文</a> <a href="##">英文</a> </li>
</ul>
<div class="admin">
<iframe scrolling="auto" rameborder="0" src="saveUser.jsp" name="right" width="100%" height="100%"></iframe>
</div>
<div style="text-align:center;">
</div>
</body>
</html>
listUser.jsp----展示所有用户界面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<base href="<%=request.getContextPath()+"/"%>">
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
</head>
<body>
<form method="post" action="" id="listform">
<div class="panel admin-panel">
<div class="panel-head"><strong class="icon-reorder"> 用户列表</strong> <a href="" style="float:right; display:none;">添加字段</a></div>
<div class="padding border-bottom">
<ul class="search" style="padding-left:10px;">
<li>
用户名:
<input type="text" placeholder="请输入搜索关键字" name="keywords" class="input" style="width:250px; line-height:17px;display:inline-block" />
手机号:
<input type="text" placeholder="请输入搜索关键字" name="keywords" class="input" style="width:250px; line-height:17px;display:inline-block" />
<a href="javascript:void(0)" class="button border-main icon-search" onclick="changesearch()" > 搜索</a>
</li>
</ul>
</div>
<table class="table table-hover text-center">
<tr>
<th width="100" style="text-align:left; padding-left:20px;">ID</th>
<th width="10%">姓名</th>
<th>手机号</th>
<th>性别</th>
<th>出生年月</th>
<th width="310">操作</th>
</tr>
<c:set var="count" value="0"></c:set>
<c:set var="manCount" value="0"></c:set>
<c:forEach items="${user}" var="us" varStatus="vs">
<c:if test="${vs.count%3==1}">
<tr bgcolor="#fafad2">
</c:if>
<c:if test="${vs.count%3==2}">
<tr bgcolor="#ffffe0">
</c:if>
<c:if test="${vs.count%3==0}">
<tr bgcolor="#fffff0">
</c:if>
<td style="text-align:left; padding-left:20px;">${us.id}</td>
<td>${us.uname}</td>
<td>${us.phone}</td>
<td>${us.sex}</td>
<td><fmt:formatDate value="${us.birth}" pattern="yyyy-MM-dd"></fmt:formatDate></td>
<td><div class="button-group"> <a class="button border-main" href="servlet/UserServlet?method=userFindOne&id=${us.id}"><span class="icon-edit"></span>修改</a>
<a class="button border-red" href="javascript:void(0)" onclick="return del(${us.id})"><span class="icon-trash-o"></span> 删除</a> </div></td>
</tr>
<c:set var="count" value="${count+1}"></c:set>
<c:if test="${us.sex=='男'}">
<c:set var="manCount" value="${manCount+1}"></c:set>
</c:if>
</c:forEach>
<tr>
<td colspan="8">
<div class="pagelist">
总人数是:${count},男:${manCount},女:${count-manCount}
</div>
</td>
</tr>
<tr>
<td colspan="8"><div class="pagelist"> <a href="">上一页</a> <span class="current">1</span><a href="">2</a><a href="">3</a><a href="">下一页</a><a href="">尾页</a> </div></td>
</tr>
</table>
</div>
</form>
<script type="text/javascript">
//搜索
function changesearch(){
}
//单个删除
function del(uu){
var flag = confirm("您确定要删除吗?");
if(flag){
window.location.href="servlet/UserServlet?method=userDelete&id="+uu;
}
}
//全选
$("#checkall").click(function(){
$("input[name='id[]']").each(function(){
if (this.checked) {
this.checked = false;
}
else {
this.checked = true;
}
});
})
//批量删除
function DelSelect(){
var Checkbox=false;
$("input[name='id[]']").each(function(){
if (this.checked==true) {
Checkbox=true;
}
});
if (Checkbox){
var t=confirm("您确认要删除选中的内容吗?");
if (t==false) return false;
$("#listform").submit();
}
else{
alert("请选择您要删除的内容!");
return false;
}
}
//批量排序
function sorts(){
var Checkbox=false;
$("input[name='id[]']").each(function(){
if (this.checked==true) {
Checkbox=true;
}
});
if (Checkbox){
$("#listform").submit();
}
else{
alert("请选择要操作的内容!");
return false;
}
}
//批量首页显示
function changeishome(o){
var Checkbox=false;
$("input[name='id[]']").each(function(){
if (this.checked==true) {
Checkbox=true;
}
});
if (Checkbox){
$("#listform").submit();
}
else{
alert("请选择要操作的内容!");
return false;
}
}
//批量推荐
function changeisvouch(o){
var Checkbox=false;
$("input[name='id[]']").each(function(){
if (this.checked==true) {
Checkbox=true;
}
});
if (Checkbox){
$("#listform").submit();
}
else{
alert("请选择要操作的内容!");
return false;
}
}
//批量置顶
function changeistop(o){
var Checkbox=false;
$("input[name='id[]']").each(function(){
if (this.checked==true) {
Checkbox=true;
}
});
if (Checkbox){
$("#listform").submit();
}
else{
alert("请选择要操作的内容!");
return false;
}
}
//批量移动
function changecate(o){
var Checkbox=false;
$("input[name='id[]']").each(function(){
if (this.checked==true) {
Checkbox=true;
}
});
if (Checkbox){
$("#listform").submit();
}
else{
alert("请选择要操作的内容!");
return false;
}
}
//批量复制
function changecopy(o){
var Checkbox=false;
$("input[name='id[]']").each(function(){
if (this.checked==true) {
Checkbox=true;
}
});
if (Checkbox){
var i = 0;
$("input[name='id[]']").each(function(){
if (this.checked==true) {
i++;
}
});
if(i>1){
alert("只能选择一条信息!");
$(o).find("option:first").prop("selected","selected");
}else{
$("#listform").submit();
}
}
else{
alert("请选择要复制的内容!");
$(o).find("option:first").prop("selected","selected");
return false;
}
}
</script>
</body>
</html>
saveUser.jsp----添加用户界面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title>添加用户</title>
<base href="<%=request.getContextPath()+"/"%>">
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel">
<div class="panel-head"><strong><span class="icon-pencil-square-o"></span>添加用户</strong></div>
<div class="body-content">
<form method="post" class="form-x" action="servlet/UserServlet?method=userSave">
<div class="form-group">
<div class="label">
<label>用户名:</label>
</div>
<div class="field">
<input type="text" class="input" name="uname" value="" style="width:30%"/>
<div class="tips"></div>
</div>
</div>
<div class="form-group">
<div class="label">
<label>密码:</label>
</div>
<div class="field">
<input type="text" class="input" name="pwd" value="" style="width:30%"/>
</div>
</div>
<div class="form-group">
<div class="label">
<label>性别:</label>
</div>
<div class="field" style="padding-top:8px;">
男:<input type="radio" name="sex" value="男" />
女: <input type="radio" name="sex" value="女" />
</div>
</div>
<div class="form-group">
<div class="label">
<label>爱好:</label>
</div>
<div class="field" style="padding-top:8px;">
抽烟 <input type="checkbox" name="hobby" value="chouyan"/>
喝酒 <input type="checkbox" name="hobby" value="hejiu"/>
烫头 <input type="checkbox" name="hobby" value="tangtou"/>
</div>
</div>
<div class="form-group">
<div class="label">
<label>出生年月:</label>
</div>
<div class="field">
<input type="date" class="input" name="birth" value="" style="width:30%"/>
<div class="tips"></div>
</div>
</div>
<div class="form-group">
<div class="label">
<label>手机号:</label>
</div>
<div class="field">
<input type="text" class="input" name="phone" value="" style="width:30%"/>
</div>
</div>
<div class="form-group">
<div class="label">
<label>描述:</label>
</div>
<div class="field">
<textarea type="text" class="input" name="remark" style="height:80px;"></textarea>
</div>
</div>
<div class="form-group">
<div class="label">
<label></label>
</div>
<div class="field">
<button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
</div>
</div>
</form>
</div>
</div>
</body></html>
updateUser.jsp----修改用户界面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title>修改用户</title>
<base href="<%=request.getContextPath()+"/"%>">
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel">
<div class="panel-head"><strong><span class="icon-pencil-square-o"></span>修改用户</strong></div>
<div class="body-content">
<form method="post" class="form-x" action="servlet/UserServlet?method=userChange">
<input type="hidden" name="id" value="${user.id}"/>
<div class="form-group">
<div class="label">
<label>用户名:</label>
</div>
<div class="field">
<input type="text" class="input" name="uname" value="${user.uname}" style="width:30%"/>
<div class="tips"></div>
</div>
</div>
<div class="form-group">
<div class="label">
<label>密码:</label>
</div>
<div class="field">
<input type="text" class="input" name="pwd" value="${user.pwd}" style="width:30%"/>
</div>
</div>
<div class="form-group">
<div class="label">
<label>性别:</label>
</div>
<div class="field" style="padding-top:8px;">
男:<input type="radio" name="sex" value="男" <c:if test="${user.sex=='男'}">checked</c:if> />
女: <input type="radio" name="sex" value="女" <c:if test="${user.sex=='女'}">checked</c:if>/>
</div>
</div>
<div class="form-group">
<div class="label">
<label>爱好:</label>
</div>
<div class="field" style="padding-top:8px;">
抽烟 <input type="checkbox" name="hobby" value="chouyan"/>
喝酒 <input type="checkbox" name="hobby" value="hejiu"/>
烫头 <input type="checkbox" name="hobby" value="tangtou"/>
</div>
</div>
<div class="form-group">
<div class="label">
<label>出生年月:</label>
</div>
<div class="field">
<input type="date" class="input" name="birth" value="<fmt:formatDate value="${user.birth}" pattern="yyyy-MM-dd"></fmt:formatDate>" style="width:30%"/>
<div class="tips"></div>
</div>
</div>
<div class="form-group">
<div class="label">
<label>手机号:</label>
</div>
<div class="field">
<input type="text" class="input" name="phone" value="${user.phone}" style="width:30%"/>
</div>
</div>
<div class="form-group">
<div class="label">
<label>描述:</label>
</div>
<div class="field">
<textarea type="text" class="input" name="remark" style="height:80px;">${user.remark}</textarea>
</div>
</div>
<div class="form-group">
<div class="label">
<label></label>
</div>
<div class="field">
<button class="button bg-main icon-check-square-o" type="submit">确认修改</button>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
数据库设计
PS:entity包中的Student.java和jstlel.jsp是练手的,与本项目无关,就不展示了