基于javaweb+jsp的校园快递管理系统
JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Bootstrap Ajax
基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可
开发工具:eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
modal.find('#info-expressPhone').text(vo.expressPhone);
modal.find('#info-expressArea').text(vo.expressArea);
modal.find('#info-expressStatus').text(vo.expressStatus);
modal.find('#info-expressSign').text(vo.expressSign);
modal.find('#info-expressTime').text(vo.expressTime);
modal.find('#info-expressText').text(vo.expressText);
}
})
})
function searchList() {
window.location.href = "ExpressServlet?action=list&searchColumn="+document.getElementById("searchColumn").value+"&keyword=" + document.getElementById("search_keyword").value;
}
//增加表单提交之前进行检查,如果return false,则不允许提交
function addCheck() {
//根据ID获取值
if (document.getElementById("add-expressNo").value.trim().length == 0) {
alert("单号不能为空");
return false;
}
if (document.getElementById("add-expressName").value.trim().length == 0) {
alert("收件人不能为空");
return false;
}
if (document.getElementById("add-expressPhone").value.trim().length == 0) {
})
$('#modal-edit').on('show.bs.modal', function (event) {
let button = $(event.relatedTarget);
let id = button.data('id');
let modal = $(this);
$.ajax({
url: 'NoticeServlet?action=get&id=' + id,
type: "get",
success: function (voString) {
let vo = eval('(' + voString + ')');
modal.find('#edit-id').val(vo.id);
modal.find('#edit-noticeName').val(vo.noticeName);
//取出表要删除的用户记录的主键
long id = Long.parseLong(Util.decode(request, "id"));
UserService userService = new UserServiceImpl();
//调用Service层删除方法(delete),将对应的记录删除
userService.delete(id);
this.redirectList(request, response);
} else if ("edit".equals(action)) {//修改
//取出页面传进来的各个数据,并设置到User对象的属性里
User vo = new User();
vo.setId(Long.valueOf(Util.decode(request, "id")));
<div class="loginBtn">
<button type="submit" class=" btn btn-line btn-info loginBtn">注册button>
div>
<br>
<br>
form>
div>
div>
body>
<script type="text/javascript">
//提交之前进行检查,如果return false,则不允许提交
function check() {
//根据ID获取值
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var password2 = document.getElementById("password2").value;
if (username == "") {
alert("用户名不能为空!");
}
//@Override
public Map<String, Object> list(Map<String, Object> params) {
List<Notice> 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_notice` where 1=1 " + condition + " order by id asc " + limit + ";";
ps = c.prepareStatement(sqlList);
<div class="col-sm-3 col-md-2 sidebar">
<jsp:include page="menu.jsp">
<jsp:param value="active" name="Notice_active"/>
jsp:include>
div>
<br>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<div class="row">
<div class="col-sm-7">
<div class="input-group">
<input class="form-control" type="hidden" id="searchColumn" name="searchColumn" value="notice_name"/>
<input class="form-control" type="text" id="search_keyword" name="search_keyword" placeholder="标题"/> <span class="input-group-btn"><button class="btn btn-line btn-primary" type="button" onclick="searchList()">搜索button>span>
div>
div>
<div class="col-sm-5">
<button type="button" if test="${loginUser.userType != '管理员'}">disabled="disabled" title="没有权限!!!"c:if> class="btn btn-line btn-success" data-toggle="modal" data-target="#modal-add">添加公告
button>
div>
div>
<th>类型th>
<th>创建时间th>
<th style="text-align: center;">操作th>
tr>
thead>
<tbody>
<c:forEach items="${list}" var="vo">
<tr>
<td>${vo.noticeName}td>
<td title="${vo.noticeText}">
<c:choose>
<c:when test="${fn:length(vo.noticeText) > 19}">
<c:out value="${fn:substring(vo.noticeText, 0, 19)}..."/>
c:when>
<c:otherwise>
<c:out value="${vo.noticeText}"/>
c:otherwise>
c:choose>
td>
alert("区域不能为空");
return false;
}
if (document.getElementById("edit-expressSign").value.trim().length == 0) {
alert("签收人不能为空");
return false;
}
if (document.getElementById("edit-expressTime").value.trim().length == 0) {
alert("签收日期不能为空");
return false;
div>
div>
div>
body>
<script>
$('#modal-delete').on('show.bs.modal', function (event) {
let button = $(event.relatedTarget);
let id = button.data('id');
let modal = $(this);
modal.find('#delete-id').val(id);
})
$('#modal-edit').on('show.bs.modal', function (event) {
let button = $(event.relatedTarget);
e.printStackTrace();
}
Map<String, Object> result = new HashMap();
result.put("list", list);
result.put("totalCount", totalCount);
return result;
}
}
package com.demo.servlet;
import com.demo.util.Util;
import com.demo.service.UserService;
*/
//@WebServlet("/NoticeServlet")
public class NoticeServlet extends HttpServlet {
/**
* 处理Post请求
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
chLength++;
}
}
return count / chLength > 0.4;
}
/**
* 为防止页面传进来的内容因为编码不同等原因造成乱码,这里作统一的转换
*
* @param parameterName
* @return
*/
public static String decode(javax.servlet.http.HttpServletRequest request, String parameterName) {
String str;
if ((str = request.getParameter(parameterName)) == null) {
return null;
}
try {
if (isMessyCode(str)) {
* 快递模块的DAO层(数据层)的具体实现类,对ExpressDAO接口中定义的增删改查等抽象方法作出具体的功能实现
*/
public class ExpressDAOImpl implements ExpressDAO {
//@Override
public void add(Express vo) {
String sql = "insert into `t_express` (`express_no`,`express_name`,`express_phone`,`express_area`,`express_status`,`express_sign`,`express_time`,`express_text`) values(?,?,?,?,?,?,?,?)";
try {
Connection c = Util.getConnection();
PreparedStatement ps = c.prepareStatement(sql);
ps.setString(1, vo.getExpressNo());
aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form action="UserServlet" onsubmit="return addCheck()">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×span>
button>
<h4 class="modal-title" id="myModalLabel">增加用户h4>
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());
String keyword = Util.decode(request, "keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
NoticeService noticeService = new NoticeServiceImpl();
Map<String, Object> map = noticeService.list(params);
request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
String pageNum = Util.decode(request, "pageNum");//封装分页参数
com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
params.put("startIndex", pb.getStartIndex());
params.put("pageSize", pb.getPageSize());
List list = (List) noticeService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
<div class="form-group">
<label class="control-label">性别:label>
<input name="userSex" id="add-userSex_男" type="radio" value="男" checked="checked"/>男
<input name="userSex" id="add-userSex_女" type="radio" value="女"/>女
div>
<div class="form-group">
<label for="add-userPhone" class="control-label">手机:label>
<input type="text" class="form-control" name="userPhone" id="add-userPhone">
div>
<div class="form-group">
<label for="add-userText" class="control-label">备注:label>
<textarea style="height: 100px;" class="form-control" name="userText" id="add-userText">textarea>
vo.setNoticeName(rs.getString("notice_name"));
vo.setNoticeText(rs.getString("notice_text"));
vo.setNoticeType(rs.getString("notice_type"));
vo.setCreateDate(rs.getString("create_date"));
}
c.close();
} catch (Exception e) {
e.printStackTrace();
}
return vo;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalPage() {
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//过滤编码
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String action = Util.decode(request, "action");
if ("add".equals(action)) {//增加
Notice vo = new Notice();
//取出页面传进来的各个数据,并设置到Notice对象的属性里
vo.setNoticeName(Util.decode(request, "noticeName"));
vo.setNoticeText(Util.decode(request, "noticeText"));
vo.setNoticeType(Util.decode(request, "noticeType"));
vo.setCreateDate(Util.decode(request, "createDate"));
NoticeService noticeService = new NoticeServiceImpl();
//调用Service层增加方法(add),增加记录
noticeService.add(vo);
this.redirectList(request, response);
} else if ("delete".equals(action)) {//删除
//取出表要删除的公告记录的主键
long id = Long.parseLong(Util.decode(request, "id"));
NoticeService noticeService = new NoticeServiceImpl();
//调用Service层删除方法(delete),将对应的记录删除
noticeService.delete(id);
div>
div>
<br>
<br>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>标题th>
<th>内容th>
<th>类型th>
<th>创建时间th>
<th style="text-align: center;">操作th>
tr>
thead>
<tbody>
<c:forEach items="${list}" var="vo">
<tr>
<td>${vo.noticeName}td>
<td title="${vo.noticeText}">
<c:choose>
<div class="col-sm-3 col-md-2 sidebar">
<jsp:include page="menu.jsp">
<jsp:param value="active" name="Notice_active"/>
jsp:include>
div>
<br>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<div class="row">
<div class="col-sm-7">
<div class="input-group">
<input class="form-control" type="hidden" id="searchColumn" name="searchColumn" value="notice_name"/>
<input class="form-control" type="text" id="search_keyword" name="search_keyword" placeholder="标题"/> <span class="input-group-btn"><button class="btn btn-line btn-primary" type="button" onclick="searchList()">搜索button>span>
div>
div>
<div class="col-sm-5">
<button type="button" if test="${loginUser.userType != '管理员'}">disabled="disabled" title="没有权限!!!"c:if> class="btn btn-line btn-success" data-toggle="modal" data-target="#modal-add">添加公告
button>
div>
div>
User vo = new User();
vo.setId(rs.getLong("id"));
vo.setUsername(rs.getString("username"));
vo.setPassword(rs.getString("password"));
vo.setRealName(rs.getString("real_name"));
vo.setUserSex(rs.getString("user_sex"));
vo.setUserPhone(rs.getString("user_phone"));
vo.setUserText(rs.getString("user_text"));
vo.setUserType(rs.getString("user_type"));
list.add(vo);
}
String sqlCount = "select count(*) from `t_user` where 1=1 " + condition;
ps = c.prepareStatement(sqlCount);
rs = ps.executeQuery();
public void setKeyword(String keyword) {
this.keyword = keyword;
}
}
package com.demo.vo;
import java.io.Serializable;
/**
* 快递(t_express表对应的Java实体类)
*/
this.expressText = expressText;
}
}
<%@ 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" %>
DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>快递管理title>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/main.css">
<script src="js/jquery-3.5.1.js">script>
<script src="js/bootstrap.js">script>
head>
<body>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">欢迎:<span style="color: yellow">${loginUser.username}span>a>li>
<li><a href="AuthServlet?action=logout">退出a>li>
ul>
div>
div>
nav>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<jsp:include page="menu.jsp">
<jsp:param value="active" name="Notice_active"/>
jsp:include>
div>
<br>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<div class="row">
<div class="col-sm-7">
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
//@Override
public Express get(Serializable id) {
Express vo = null;
try {
Connection c = Util.getConnection();
Statement s = c.createStatement();
<div class="modal-dialog" role="document">
<div class="modal-content">
<form action="UserServlet">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×span>
button>
<h4 class="modal-title">删除用户h4>
div>
<div class="modal-body">
确认要删除该用户记录吗?
<div class="form-group hidden">
/**
* 取得数据库连接对象
*
* @return 如果连接成功则返回连接对象,如果连接失败返回null
*/
public static Connection getConnection() throws Exception {
Class.forName(DBDRIVER);
return DriverManager.getConnection(DBURL, DBUSER, PASSWORD);
}
/**
* 测试连接是否成功
*
* @param args
* @throws Exception
*/
public static void main(String[] args) {
try {
Connection conn = Util.getConnection();
System.out.println("数据库连接成功!!!");
conn.close();
} catch (Exception e) {
e.printStackTrace();
System.out.println("数据库连接失败!!!");
}
运行环境
Java≥6、Tomcat≥7.0、MySQL≥5.5
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Bootstrap Ajax
基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
登录、注册、退出、用户模块、公告模块、快递模块的增删改查管理