基于javaweb+mysql的jsp+servlet大学实验室设备管理系统(java+jsp+easyui+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet大学实验室设备管理系统(java+jsp+easyui+mysql)
项目介绍
本项目为后台管理系统,主要功能如下: 管理员登录,管理数据字典,设备信息管理,进购管理,报损管理,查看库存,账号管理等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目:否;
技术栈
HTML+CSS+JavaScript+JSP+jquery+easyui+mysql
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中dbpool.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入http://localhost:8080/jsp_dxsys_sys/ 登录 管理员账号密码:admin/admin
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class GoodsService {
DBUtil dbUtil = new DBUtil();
ResultSet rs = null;
/**
* 商品记录
* @param pageBean
* @param goods
* @return
*/
public ResultSet goodsList (PageBean pageBean, Goods goods,Connection conn) {
// Connection conn = dbUtil.getConnection();
StringBuffer sb = new StringBuffer("SELECT * FROM t_goods");
if(goods != null && StringUtil.isNotEmpty(goods.getGoodsname())) {
sb.append(" AND goodsname LIKE '%"+ goods.getGoodsname() +"%'");
}
if(goods != null && StringUtil.isNotEmpty(goods.getSupplier())) {
sb.append(" AND supplier LIKE '%"+ goods.getSupplier() +"%'");
}
if(goods != null && StringUtil.isNotEmpty(goods.getType())) {
sb.append(" AND type LIKE '%"+ goods.getType() +"%'");
}
if(pageBean!=null){
sb.append(" LIMIT "+pageBean.getStart()+","+pageBean.getRows());
}
PreparedStatement pstm = null;
try {
pstm = conn.prepareStatement(sb.toString().replaceFirst("AND", "WHERE"));
return pstm.executeQuery();
} catch (Exception e) {
e.printStackTrace();
}
// finally {
// dbUtil.close(conn, pstm, rs);
DBUtil dbUtil = new DBUtil();
ResultSet rs = null;
/**
* 登录验证
*
* @param user
* @return User
*/
public User login (User user) {
Connection conn = dbUtil.getConnection();
String sql = "select * from t_user where username=? and password=?";
User u = null;
PreparedStatement pstm = null;
try {
pstm = conn.prepareStatement(sql);
pstm.setString(1, user.getUsername());
pstm.setString(2, user.getPassword());
rs = pstm.executeQuery();
while(rs.next()) {
u = new User();
u.initFormRs(rs);
}
}catch (SQLException e) {
e.printStackTrace();
} finally {
dbUtil.close(conn, pstm, rs);
}
return u;
}
public String logout() {
return null;
}
/**
* 管理员记录数
* @param currentuser
* @return
*/
public int getTotal(User currentuser, String s_username) {
int total = 0;
Connection conn = dbUtil.getConnection();
StringBuffer sb = new StringBuffer("SELECT COUNT(*) AS total FROM t_user");
if(currentuser != null && StringUtil.isNotEmpty(s_username)) {
sb.append(" AND username LIKE '%"+ s_username +"%'");
}
sb.append(" WHERE id != ?");
String sql = sb.toString().replaceFirst("AND", "WHERE");
PreparedStatement pstm = null;
try {
pstm = conn.prepareStatement(sql);
public class UserAction extends ActionSupport implements ServletRequestAware {
private String page;
private String rows;
private String s_username;
private User user;
private String delIds;
private String id;
private List<User> users;
private String error;
private String imageCode;
private String old_password;
UserService userService = new UserService();
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session;
public void setServletRequest(HttpServletRequest request) {
// TODO Auto-generated method stub
this.request = request;
//获取Session
session = request.getSession();
}
public String index() {
if(StringUtil.isEmpty(user.getUsername()) || StringUtil.isEmpty(user.getPassword())){
error = "用户名或密码为空!";
return ERROR;
}
if(StringUtil.isEmpty(imageCode)) {
error = "验证码为空!";
return ERROR;
}
if(!imageCode.equals(session.getAttribute("sRand"))) {
error = "验证码错误!";
return ERROR;
}
User currentuser = userService.login(user);
if(currentuser == null) {
error = "用户名或密码错误!";
return ERROR;
} else {
session = request.getSession();
session.setAttribute("currentuser", currentuser);
return SUCCESS;
}
}
private String id; // 库存ID
private String delIds; // 批量删除ID
DBUtil dbUtil = new DBUtil();
ResultSet rs = null;
KucunService kucunService = new KucunService();
public String execute() throws SQLException{
Connection conn = dbUtil.getConnection();
PageBean pageBean = new PageBean (Integer.parseInt(page), Integer.parseInt(rows));
try {
if(kucun == null) {
kucun = new Kucun();
}
JSONObject result = new JSONObject();
JSONArray jsonArray = JsonUtil.formatRsToJsonArray(kucunService.kucunList(conn, pageBean, kucun));
int total = kucunService.kucunListTotal(conn, kucun);
result.put("rows", jsonArray);
result.put("total", total);
ResponseUtil.write(ServletActionContext.getResponse(), result);
} catch (Exception e) {
e.printStackTrace();
} finally {
dbUtil.close(conn, null, rs);
}
return null;
}
/*******************GETTER/SETTER*********************/
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public String getRows() {
return rows;
}
public void setRows(String rows) {
this.rows = rows;
}
public Kucun getKucun() {
return kucun;
}
User currentuser = userService.login(user);
if(currentuser == null) {
error = "用户名或密码错误!";
return ERROR;
} else {
session = request.getSession();
session.setAttribute("currentuser", currentuser);
return SUCCESS;
}
}
public String logout() {
return "logout";
}
@Override
public String execute() throws Exception {
int total = 0;
PageBean pageBean = new PageBean (Integer.parseInt(page), Integer.parseInt(rows));
User user = (User)session.getAttribute("currentuser");
total = userService.getTotal(user, s_username);
JSONObject result = new JSONObject();
JSONArray jsonArray = JsonUtil.formatRsToJsonArray(userService.queryForAll(user, pageBean, s_username));
result.put("rows", jsonArray);
result.put("total", total);
ResponseUtil.write(ServletActionContext.getResponse(), result);
return null;
}
public String delete()throws Exception{
JSONObject result=new JSONObject();
int delNums=userService.delete(delIds);
if(delNums>0){
result.put("success", "true");
result.put("delNums", delNums);
}else{
result.put("errorMsg", "删除失败");
}
ResponseUtil.write(ServletActionContext.getResponse(), result);
return null;
}
public String save()throws Exception{
int saveNums=0;
JSONObject result=new JSONObject();
if(StringUtil.isNotEmpty(id)){
user.setId(Integer.parseInt(id));
}
},{
text:"库存查看",
attributes:{
url:"<%=path %>/dynamic/server/kucun/page.jsp"
}
},{
text:"账号管理",
attributes:{
url:"<%=path %>/dynamic/server/user/page.jsp"
}
}]
}];
// 实例化树菜单
$("#tree").tree({
data:treeData,
lines:true,
onClick:function(node){
if(node.attributes){
openTab(node.text,node.attributes.url);
}
}
});
// 新增Tab
function openTab(text,url){
if($("#tabs").tabs('exists',text)){
$("#tabs").tabs('select',text);
}else{
var content="<iframe frameborder='0' scrolling='auto' style='width:100%;height:100%' src="+url+"></iframe>";
$("#tabs").tabs('add',{
title:text,
closable:true,
content:content
});
}
}
});
animate: true,
collapsible: true,
fitColumns: true,
url: '../treegrid/treegrid_data2.json',
idField: 'id',
treeField: 'name',
onContextMenu: onContextMenu
">
<thead>
<tr>
<th data-options="field:'name',width:180">Task Name</th>
<th data-options="field:'persons',width:60,align:'right'">Persons</th>
<th data-options="field:'begin',width:80">Begin Date</th>
<th data-options="field:'end',width:80">End Date</th>
<th data-options="field:'progress',width:120,formatter:formatProgress">Progress</th>
</tr>
</thead>
</table>
<div id="mm" class="easyui-menu" style="width:120px;">
<div onclick="append()" data-options="iconCls:'icon-add'">Append</div>
<div onclick="removeIt()" data-options="iconCls:'icon-remove'">Remove</div>
<div class="menu-sep"></div>
<div onclick="collapse()">Collapse</div>
<div onclick="expand()">Expand</div>
</div>
<script type="text/javascript">
function formatProgress(value){
if (value){
var s = '<div style="width:100%;border:1px solid #ccc">' +
'<div style="width:' + value + '%;background:#cc0000;color:#fff">' + value + '%' + '</div>'
'</div>';
return s;
} else {
return '';
}
}
function onContextMenu(e,row){
e.preventDefault();
$(this).treegrid('select', row.id);
$('#mm').menu('show',{
left: e.pageX,
top: e.pageY
});
}
var idIndex = 100;
function append(){
PageBean pageBean = new PageBean (Integer.parseInt(page), Integer.parseInt(rows));
try {
if(dictionary == null) {
dictionary = new Dictionary();
}
dictionary.setName(s_name);
dictionary.setValue(s_value);
JSONObject result = new JSONObject();
JSONArray jsonArray = JsonUtil.formatRsToJsonArray(dictionaryService.dictionaryList(conn, pageBean, dictionary));
int total = dictionaryService.dictionaryListTotal(conn, dictionary);
result.put("rows", jsonArray);
result.put("total", total);
ResponseUtil.write(ServletActionContext.getResponse(), result);
} catch (Exception e) {
e.printStackTrace();
} finally {
dbUtil.close(conn, null, rs);
}
return null;
}
public String delete () throws SQLException {
Connection conn = dbUtil.getConnection();
try {
JSONObject result = new JSONObject();
String str [] = delIds.split(",");
for(int i = 0; i < str.length; i++) {
boolean f = goodsService.getGoodsByDictionaryId(conn, str[i]);
if(f) {
result.put("errorIndex", i);
result.put("errorMsg", "该数据下面有商品,不能删除!");
ResponseUtil.write(ServletActionContext.getResponse(), result);
return null;
}
}
int delNums = dictionaryService.dictionaryDelete(conn, delIds);
if(delNums > 0 ) {
result.put("success", "true");
result.put("delNums", delNums);
} else {
result.put("errorMsg", "删除失败");
}
ResponseUtil.write(ServletActionContext.getResponse(), result);
} catch (Exception e) {
e.printStackTrace();
} finally {
dbUtil.close(conn, null, rs);
}
e.printStackTrace();
throw (e);
} finally {
dbUtil.close(conn, null, rs);
}
return null;
}
/*********************GETTER/SETTER*******************/
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public String getRows() {
return rows;
}
public void setRows(String rows) {
this.rows = rows;
}
public Jinhuo getJinhuo() {
return jinhuo;
}
public void setJinhuo(Jinhuo jinhuo) {
this.jinhuo = jinhuo;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getS_goodsid() {
return s_goodsid;
}
public void setS_goodsid(String s_goodsid) {
this.s_goodsid = s_goodsid;
}
public String getS_intodate() {
return s_intodate;
}
public void setS_intodate(String s_intodate) {
}
public void setPage(String page) {
this.page = page;
}
public String getRows() {
return rows;
}
public void setRows(String rows) {
this.rows = rows;
}
public String getS_goodsname() {
return s_goodsname;
}
public void setS_goodsname(String s_goodsname) {
this.s_goodsname = s_goodsname;
}
public String getS_supplier() {
return s_supplier;
}
public void setS_supplier(String s_supplier) {
this.s_supplier = s_supplier;
}
public String getS_type() {
return s_type;
}
public void setS_type(String s_type) {
this.s_type = s_type;
}
public Goods getGoods() {
return goods;
}
public void setGoods(Goods goods) {
this.goods = goods;
}
public String getDelIds() {
return delIds;
}
public void setDelIds(String delIds) {
this.delIds = delIds;
}
public String getGoodsid() {
return goodsid;
}
public void setGoodsid(String goodsid) {
this.goodsid = goodsid;
}
ResponseUtil.write(ServletActionContext.getResponse(), result);
} catch (Exception e) {
e.printStackTrace();
} finally {
dbUtil.close(conn, null, rs);
}
return null;
}
public String delete () throws SQLException {
Connection conn = dbUtil.getConnection();
try {
JSONObject result = new JSONObject();
String str [] = delIds.split(",");
for(int i = 0; i < str.length; i++) {
boolean f = goodsService.getGoodsByDictionaryId(conn, str[i]);
if(f) {
result.put("errorIndex", i);
result.put("errorMsg", "该数据下面有商品,不能删除!");
ResponseUtil.write(ServletActionContext.getResponse(), result);
return null;
}
}
int delNums = dictionaryService.dictionaryDelete(conn, delIds);
if(delNums > 0 ) {
result.put("success", "true");
result.put("delNums", delNums);
} else {
result.put("errorMsg", "删除失败");
}
ResponseUtil.write(ServletActionContext.getResponse(), result);
} catch (Exception e) {
e.printStackTrace();
} finally {
dbUtil.close(conn, null, rs);
}
return null;
}
public String save() throws SQLException {
Connection conn = dbUtil.getConnection();
try {
int saveNums = 0;
JSONObject result = new JSONObject();
}
public void setS_goodsname(String s_goodsname) {
this.s_goodsname = s_goodsname;
}
public String getS_supplier() {
return s_supplier;
}
public void setS_supplier(String s_supplier) {
this.s_supplier = s_supplier;
}
public String getS_type() {
return s_type;
}
public void setS_type(String s_type) {
this.s_type = s_type;
}
public Goods getGoods() {
return goods;
}
public void setGoods(Goods goods) {
this.goods = goods;
}
public String getDelIds() {
return delIds;
}
public void setDelIds(String delIds) {
this.delIds = delIds;
}
public String getGoodsid() {
return goodsid;
}
public void setGoodsid(String goodsid) {
this.goodsid = goodsid;
}
}
pstm.setString(1, goods.getGoodsname());
pstm.setFloat(2, goods.getCost());
pstm.setFloat(3, goods.getSell());
pstm.setInt(4, goods.getSupplierId());
pstm.setString(5, goods.getSupplier());
pstm.setInt(6, goods.getTypeId());
pstm.setString(7, goods.getType());
num = pstm.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
dbUtil.close(conn, pstm, rs);
}
return num;
}
/**
* 修改商品记录
* @param goods
* @return
*/
public int goodsModify (Goods goods) {
int num = 0;
Connection conn = dbUtil.getConnection();
String sql = "UPDATE t_goods SET goodsname = ? , cost = ? , sell = ? , supplierId = ? , supplier = ? , typeId = ? , type = ? WHERE goodsid = ?";
PreparedStatement pstm = null;
try {
pstm = conn.prepareStatement(sql);
pstm.setString(1, goods.getGoodsname());
pstm.setFloat(2, goods.getCost());
pstm.setFloat(3, goods.getSell());
pstm.setInt(4, goods.getSupplierId());
pstm.setString(5, goods.getSupplier());
pstm.setInt(6, goods.getTypeId());
pstm.setString(7, goods.getType());
pstm.setInt(8, goods.getGoodsid());
num = pstm.executeUpdate();
} catch (Exception e) {
} finally {
dbUtil.close(conn, pstm, rs);
}
return num;
}
/**
* 查找商品记录 通过数据字典ID
* @param conn
</a>
</td>
</tr>
</table>
</td>
<td width="255"
background="<%=basePath%>/statics/skin/server/images/login/login_08.gif"> </td>
</tr>
</form>
</table>
</td>
</tr>
<tr>
<td height="247" valign="top"
background="<%=basePath%>/statics/skin/server/images/login/login_09.gif"><table
width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22%" height="30"> </td>
<td width="56%">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="57%"></td>
<td algin="left"><span class="STYLE5" >${error} </span>
</td>
</tr>
</table>
</td>
<td width="22%"> </td>
</tr>
<tr>
<td> </td>
<td height="30"><table width="100%" border="0"
cellspacing="0" cellpadding="0">
<tr>
<td width="44%" height="20"> </td>
</tr>
</table>
</td>
<td> </td>
</tr>
try {
Class.forName(driverClassName);
conn = java.sql.DriverManager.getConnection(url, username, password);
pool.add(conn);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
private void readConfig() {
try {
//String path = System.getProperty("user.dir") + "\\src\\dbpool.properties"; // 路径
/**
* 加载配置文件
*/
// FileInputStream is = new FileInputStream(path);
Properties props = new Properties();
props.load(getClass().getResourceAsStream("/dbpool.properties"));
/**
* 读取属性值
*/
this.driverClassName = props.getProperty("driverClassName"); // 读取数据库类型
this.username = props.getProperty("username"); // 读取账户
this.url = props.getProperty("url"); // 读取路径
this.password = props.getProperty("password"); // 读取密码
this.poolSize = Integer.parseInt(props.getProperty("poolSize")); // 读取数据库连接个数
} catch (Exception e) {
e.printStackTrace();
System.err.println("读取属性文件出错。");
}
}
/**
* 返回当前连接池的一个对象
* @return
*/
public static ConnectionPool getInstance() {
if(goods != null && StringUtil.isNotEmpty(goods.getType())) {
sb.append(" AND type LIKE '%"+ goods.getType() +"%'");
}
PreparedStatement pstm = null;
try {
pstm = conn.prepareStatement(sb.toString().replaceFirst("AND", "WHERE"));
rs = pstm.executeQuery();
if(rs.next()) {
return rs.getInt("total");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
dbUtil.close(conn, pstm, rs);
}
return 0;
}
/**
* 批量删除记录
* @param delIds
* @return
*/
public int goodsDelete (String delIds) {
int num = 0;
Connection conn = dbUtil.getConnection();
String sql = "DELETE FROM t_goods WHERE goodsid IN ("+ delIds +")";
PreparedStatement pstm = null;
try {
pstm = conn.prepareStatement(sql);
num = pstm.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally {
dbUtil.close(conn, pstm, rs);
}
return num;
}
/**
* 添加商品记录
* @param goods
* @return
*/
public int goodsAdd(Goods goods) {
int num = 0;
Connection conn = dbUtil.getConnection();
String sql = "INSERT INTO t_goods (goodsname, cost, sell, supplierId, supplier, typeId, type) VALUES (?, ?, ?, ?, ?, ?, ?)";
PreparedStatement pstm = null;
}
public void setGoodsname(String goodsname) {
this.goodsname = goodsname;
}
}
public class Chuhuo {
private int id; // 编号
private int goodsid = -1; // 商品ID
private int quantity; // 数量
private Date outtime; //日期
private String goodsname; // 商品名称
/**************GETTER/SETTER**************/
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getGoodsid() {
return goodsid;
}
public void setGoodsid(int goodsid) {
this.goodsid = goodsid;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public Date getOuttime() {
id: idIndex,
name: 'New Task'+idIndex,
persons: parseInt(Math.random()*10),
begin: $.fn.datebox.defaults.formatter(d1),
end: $.fn.datebox.defaults.formatter(d2),
progress: parseInt(Math.random()*100)
}]
})
}
function removeIt(){
var node = $('#tg').treegrid('getSelected');
if (node){
$('#tg').treegrid('remove', node.id);
}
}
function collapse(){
var node = $('#tg').treegrid('getSelected');
if (node){
$('#tg').treegrid('collapse', node.id);
}
}
function expand(){
var node = $('#tg').treegrid('getSelected');
if (node){
$('#tg').treegrid('expand', node.id);
}
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Editable TreeGrid - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
<link rel="stylesheet" type="text/css" href="../demo.css">