JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Layui Ajax
基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可
开发工具:eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
},
{
field: 'realName',
title: '姓名',
templet: vo => (vo = vo.realName) ? '<a href="#" style="color: #009688;">' + vo + '</a>' : '',
event: 'info',
},
{
field: 'userSex',
title: '性别',
templet: vo => vo.userSex ? vo.userSex : "",
},
background-image: linear-gradient(to right, #a6c1ee, #fbc2eb);
color: #fff;
}
.login-wrapper .msg {
text-align: center;
line-height: 80px;
}
.login-wrapper .msg a {
/* 消除下划线 */
text-decoration: none;
text-decoration-color: none;
color: #a6c1ee;
}
</style>
</head>
<body>
<div class="container">
<div class="login-wrapper">
<div class="header">Sign up</div>
<div class="form-wrapper">
<form action="AuthServlet?action=register" method="post" id="loginForm" onsubmit="return check()">
});
//监听工具条
table.on('tool(myTable)', function (obj) { //注:tool 是工具条事件名,myTable 是 table 原始容器的属性 lay-filter="对应的值"
let data = obj.data; //获得当前行数据
let layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
if (layEvent === 'del') { //删除
// layer.confirm('删除' + data.realName + "?", function (index) {
$.ajax({
type: "GET",
dataType: "text",
url: "UserServlet?action=delete&id=" + data.id,
success: function () {
console.log("已删除!");
}
});
}
}
]
],
});
//监听工具条
table.on('tool(myTable)', function (obj) { //注:tool 是工具条事件名,myTable 是 table 原始容器的属性 lay-filter="对应的值"
let data = obj.data; //获得当前行数据
let layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
if (layEvent === 'del') { //删除
// layer.confirm('删除' + data.noticeName + "?", function (index) {
$.ajax({
type: "GET",
dataType: "text",
ps.setString(2, vo.getContactSex());
ps.setString(3, vo.getContactType());
ps.setString(4, vo.getContactPhone());
ps.setString(5, vo.getContactAddress());
ps.setString(6, vo.getContactText());
ps.setLong(7, vo.getId());
ps.execute();
ps.close();
c.close();
} catch (Exception e) {
padding: 0;
margin: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
letter-spacing: .05em;
}
html {
height: 100%;
}
body {
height: 100%;
}
.container {
height: 100%;
/*background-image: linear-gradient(to right, #fbc2eb, #a6c1ee); 设置渐变色 */
padding: 0;
margin: 0;
background: url("img/1.jpg") no-repeat;
background-size: 100% 100%;
}
</div>
</div>
<!-- 内容主体区域 -->
<table class="layui-hide" id="myData" lay-filter="myTable"></table>
</div>
</div>
<script src="js/layui/layui.js"/>
<script>
//JavaScript代码区域
layui.use('element', function () {
let element = layui.element;
});
</script>
<script type="text/html" id="myToolbar">
<div class="layui-btn-container">
<c:if test="${loginUser.userType == '管理员'}"><button class='layui-btn layui-btn-sm' lay-event='add'>添加</button></c:if>
</div>
</script>
<script>
function arrayBufferToBase64(buffer) {
let binary = '';
let bytes = new Uint8Array(buffer);
let len = bytes.byteLength;
for (let i = 0; i < len; i++) {
</html>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>通讯录管理系统</title>
<link rel="stylesheet" href="js/layui/css/layui.css">
<script src="js/jquery.js"></script>
<script src="js/layer.js"></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
reload: function () {
let url = 'NoticeServlet?action=list&keyword=' + $('#search_keyword').val() + '&searchColumn=' + $('#searchColumn').val();
//执行重载
table.reload('myTable', {
url: url,
page: {
curr: 1 //重新从第 1 页开始
}
});
}
};
$('.searchTable .layui-btn').on('click', function () {
let type = $(this).data('type');
active[type] ? active[type].call(this) : '';
});
});
</script>
</body>
</html>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<script type="text/javascript">
//提交之前进行检查,如果return false,则不允许提交
function check() {
//根据ID获取值
let username = document.getElementById("username").value;
let password = document.getElementById("password").value;
let password2 = document.getElementById("password2").value;
if (username == "") {
alert("用户名不能为空!");
return false;
}
if (password == "") {
alert("密码不能为空!");
return false;
}
if (password2 != password) {
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 联系人模块的Servlet控制层,负责接收页面传过来的请求参数,根据action参数的值来确定页面要执行的具体操作<br>
* 而后再调用ContactService业务层的方法来处理具体的业务,最后将处理完成的结果返回或跳转至相应页面
*/
//@WebServlet("/ContactServlet")
public class ContactServlet extends HttpServlet {
/**
public class User implements Serializable {
private Long id;//主键
private String username;//用户名
private String password;//密码
private String realName;//姓名
private String userSex;//性别:男/女
private String userPhone;//手机
private String userText;//备注
private String userType;//类型:管理员/普通用户
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
vo.setContactName(Util.decode(request, "contactName"));
vo.setContactSex(Util.decode(request, "contactSex"));
vo.setContactType(Util.decode(request, "contactType"));
vo.setContactPhone(Util.decode(request, "contactPhone"));
vo.setContactAddress(Util.decode(request, "contactAddress"));
vo.setContactText(Util.decode(request, "contactText"));
ContactService contactService = new ContactServiceImpl();
//调用Service层增加方法(add),增加记录
contactService.add(vo);
this.redirectList(request, response);
} else if ("delete".equals(action)) {//删除
//取出表要删除的联系人记录的主键
long id = Long.parseLong(Util.decode(request, "id"));
ContactService contactService = new ContactServiceImpl();
//调用Service层删除方法(delete),将对应的记录删除
contactService.delete(id);
this.redirectList(request, response);
} else if ("edit".equals(action)) {//修改
//取出页面传进来的各个数据,并设置到Contact对象的属性里
Contact vo = new Contact();
import com.demo.util.Util;
import com.demo.vo.User;
import javax.imageio.ImageIO;
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 java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
</div>
<script src="js/layui/layui.js"/>
<script>
//JavaScript代码区域
layui.use('element', function () {
let element = layui.element;
});
</script>
<script type="text/html" id="myToolbar">
<div class="layui-btn-container">
<c:if test="${loginUser.userType == '管理员'}"><button class='layui-btn layui-btn-sm' lay-event='add'>添加</button></c:if>
</div>
</script>
<script>
function arrayBufferToBase64(buffer) {
let binary = '';
let bytes = new Uint8Array(buffer);
let len = bytes.byteLength;
for (let i = 0; i < len; i++) {
}
public void setUserText(String userText) {
this.userText = userText;
}
public String getUserType() {
return userType;
}
public void setUserType(String userType) {
this.userType = userType;
}
}
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
title: '性别',
templet: vo => vo.contactSex ? vo.contactSex : "",
},
{
field: 'contactType',
title: '关系',
},
{
field: 'contactPhone',
title: '电话',
},
{
field: 'contactAddress',
ps.setString(3, vo.getRealName());
ps.setString(4, vo.getUserSex());
ps.setString(5, vo.getUserPhone());
ps.setString(6, vo.getUserText());
ps.setString(7, vo.getUserType());
ps.execute();
ps.close();
c.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//@Override
public void update(User vo) {
String sql = "update `t_user` set `username` = ? ,`password` = ? ,`real_name` = ? ,`user_sex` = ? ,`user_phone` = ? ,`user_text` = ? ,`user_type` = ? where `id` = ?";
try {
Connection c = Util.getConnection();
PreparedStatement ps = c.prepareStatement(sql);
ps.setString(1, vo.getUsername());
ps.setString(2, vo.getPassword());
ps.setString(3, vo.getRealName());
ps.setString(4, vo.getUserSex());
public void setId(Long 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;
}
public String getRealName() {
return realName;
}
public void setRealName(String realName) {
this.realName = realName;
List<Contact> list = new ArrayList();
int totalCount = 0;
String condition = "";
String sqlList;
if (params.get("searchColumn") != null && !"".equals(params.get("searchColumn"))) {
condition += " and `" + params.get("searchColumn") + "` like '%" + params.get("keyword") + "%'";
}
try {
Connection c = Util.getConnection();
PreparedStatement ps;
ResultSet rs;
String limit = (params.get("startIndex") != null && params.get("pageSize") != null) ? " limit " + params.get("startIndex") + "," + params.get("pageSize") : "";
sqlList = "select * from `t_contact` where 1=1 " + condition + " order by id asc " + limit + ";";
ps = c.prepareStatement(sqlList);
rs = ps.executeQuery();
while (rs.next()) {
Contact vo = new Contact();
vo.setId(rs.getLong("id"));
vo.setContactName(rs.getString("contact_name"));
ImageIO.write(image, "JPEG", os);// 以JPEG格式向客户端发送图形验证码
} else if ("resetPassword".equalsIgnoreCase(action)) {
String msg;
User loginUser = (User) request.getSession().getAttribute("loginUser");
String oldPassword = Util.decode(request, "oldPassword");
if (!loginUser.getPassword().equals(oldPassword)) {
msg = "原密码错误!";
} else {
String newPassword = Util.decode(request, "newPassword");
loginUser.setPassword(newPassword);
UserService userService = new UserServiceImpl();
userService.update(loginUser);
msg = "修改成功!";
}
request.getSession().setAttribute("alert_msg", msg);
request.getRequestDispatcher("reset_password.jsp").forward(request, response);
} else {
response.sendRedirect("login.jsp");
}
}
/**
* 处理Get请求
width: 130,
templet: vo => {
let flag1 = ${loginUser.id} == vo.id;
let flag2 = ${loginUser.userType == '管理员'};
return ((flag1 || flag2) ? '<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>' : '') + ((flag2) ? '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>' : '');
}
}
]
],
});
<input type="text" name="password" lay-verify="required|password" class="layui-input" value="${vo.password}">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">姓名:</label>
<div class="layui-input-block">
<input type="text" name="realName" lay-verify="required|realName" class="layui-input" value="${vo.realName}">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">性别:</label>
<div class="layui-input-block">
<input name="userSex" type="radio" value="男" ${vo.userSex=='男'?'checked':''} class="layui-input" title="男"/>
<input name="userSex" type="radio" value="女" ${vo.userSex=='女'?'checked':''} class="layui-input" title="女"/>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">手机:</label>
<div class="layui-input-block">
<input type="text" name="userPhone" lay-verify="required|userPhone" class="layui-input" value="${vo.userPhone}">
</div>
</div>
<div class="layui-side layui-bg-black">
<div class="layui-side-scroll">
<ul class="layui-nav layui-nav-tree" lay-filter="test">
<!-- 侧边栏 -->
<jsp:include page="menu.jsp">
<jsp:param value="active" name="User_active"/>
</jsp:include>
</ul>
</div>
</div>
<div class="layui-body">
});
}
};
$('.searchTable .layui-btn').on('click', function () {
let type = $(this).data('type');
active[type] ? active[type].call(this) : '';
});
});
</script>
</body>
</html>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>注册</title>
<script type="text/javascript">
let alert_msg = '${alert_msg}';
if (alert_msg != null && alert_msg.trim() != '') {
window.alert(alert_msg);
}
运行环境
Java≥6、Tomcat≥7.0、MySQL≥5.5
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Layui Ajax
基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
登录、注册、退出、用户模块、公告模块、联系人模块的增删改查管理
↖[获取源码方式]见左侧