基于javaweb+jsp的企业车辆管理系统
JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Bootstrap
基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可
开发工具:eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
ps.setString(1, vo.getCarPai());
ps.setString(2, vo.getCarName());
ps.setString(3, vo.getCarChexing());
ps.setString(4, vo.getCarCheng());
ps.setString(5, vo.getCarIndate());
ps.setString(6, vo.getCarStatus());
ps.setString(7, vo.getCarUser());
ps.setString(8, vo.getCarPhone());
ps.setString(9, vo.getCarText());
ps.execute();
ps.close();
c.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//@Override
public void update(Car vo) {
String sql = "update `t_car` set `car_pai` = ? ,`car_name` = ? ,`car_chexing` = ? ,`car_cheng` = ? ,`car_indate` = ? ,`car_status` = ? ,`car_user` = ? ,`car_phone` = ? ,`car_text` = ? where `id` = ?";
vo.setCarPhone(Util.decode(request, "carPhone"));
vo.setCarText(Util.decode(request, "carText"));
CarService carService = new CarServiceImpl();
//调用Service层增加方法(add),增加记录
carService.add(vo);
this.redirectList(request, response);
} else if ("delete".equals(action)) {//删除
//取出表要删除的车辆记录的主键
long id = Long.parseLong(Util.decode(request, "id"));
CarService carService = new CarServiceImpl();
//调用Service层删除方法(delete),将对应的记录删除
carService.delete(id);
this.redirectList(request, response);
} else if ("edit".equals(action)) {//修改
//取出页面传进来的各个数据,并设置到Car对象的属性里
Car vo = new Car();
vo.setId(Long.valueOf(Util.decode(request, "id")));
vo.setCarPai(Util.decode(request, "carPai"));
vo.setCarName(Util.decode(request, "carName"));
vo.setCarChexing(Util.decode(request, "carChexing"));
vo.setCarCheng(Util.decode(request, "carCheng"));
UserService userService = new UserServiceImpl();
Map<String, Object> map = userService.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) userService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("UserServlet");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
// 返回一个随机颜色(Color对象)
private Color getRandomColor(int minColor, int maxColor) {
Random random = new Random();
// 保存minColor最大不会超过255
if (minColor > 255)
minColor = 255;
// 保存minColor最大不会超过255
if (maxColor > 255)
maxColor = 255;
// 获得红色的随机颜色值
int red = minColor + random.nextInt(maxColor - minColor);
// 获得绿色的随机颜色值
int green = minColor + random.nextInt(maxColor - minColor);
// 获得蓝色的随机颜色值
int blue = minColor + random.nextInt(maxColor - minColor);
return new Color(red, green, blue);
}
doPost(request, response);//Get请求和Post请求的处理是一样的,所以把request、response转交给Post方法就好
}
/**
* 根据参数,查询出条例条件的记录集合,最后将数据返回给调用处或者将数据集合设置到session域里,再跳转到对应的列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = Util.decode(request, "searchColumn");
String keyword = Util.decode(request, "keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
CarService carService = new CarServiceImpl();
Map<String, Object> map = carService.list(params);
request.getSession().setAttribute("list", map.get("list"));
return result;
}
}
package com.demo.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.text.SimpleDateFormat;
/**
* 该方法为通用的工具类,放置一些共用的方法
*/
ps.close();
c.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//@Override
public void update(Car vo) {
String sql = "update `t_car` set `car_pai` = ? ,`car_name` = ? ,`car_chexing` = ? ,`car_cheng` = ? ,`car_indate` = ? ,`car_status` = ? ,`car_user` = ? ,`car_phone` = ? ,`car_text` = ? where `id` = ?";
try {
Connection c = Util.getConnection();
PreparedStatement ps = c.prepareStatement(sql);
ps.setString(1, vo.getCarPai());
ps.setString(2, vo.getCarName());
ps.setString(3, vo.getCarChexing());
ps.setString(4, vo.getCarCheng());
}
}
/**
* 处理Get请求
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
// 返回一个随机颜色(Color对象)
private Color getRandomColor(int minColor, int maxColor) {
Random random = new Random();
// 保存minColor最大不会超过255
ps.execute();
ps.close();
c.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//@Override
public void update(Car vo) {
String sql = "update `t_car` set `car_pai` = ? ,`car_name` = ? ,`car_chexing` = ? ,`car_cheng` = ? ,`car_indate` = ? ,`car_status` = ? ,`car_user` = ? ,`car_phone` = ? ,`car_text` = ? where `id` = ?";
try {
Connection c = Util.getConnection();
<input type="text" class="form-control" id="username" name="username" value="${vo.username}">
div>
div>
<div class="form-group">
<label class="col-sm-3 control-label">密码:label>
<div class="col-sm-5">
<input type="text" class="form-control" id="password" name="password" value="${vo.password}">
div>
div>
<div class="form-group">
<label class="col-sm-3 control-label">姓名:label>
<div class="col-sm-5">
<input type="text" class="form-control" id="realName" name="realName" value="${vo.realName}">
div>
div>
vo.setUserSex(Util.decode(request, "userSex"));
vo.setUserPhone(Util.decode(request, "userPhone"));
vo.setUserText(Util.decode(request, "userText"));
vo.setUserType(Util.decode(request, "userType"));
UserService userService = new UserServiceImpl();
//调用Service层更新方法(update),更新记录
userService.update(vo);
this.redirectList(request, response);
} else if ("get".equalsIgnoreCase(action) || "editPre".equalsIgnoreCase(action)) {//根据主键ID,查询详情信息并跳转到详情页面或编辑页面
Serializable id = Util.decode(request, "id");//取出页面传入的主键,用于查询详情
UserService userService = new UserServiceImpl();
User vo = userService.get(id);
request.getSession().setAttribute("vo", vo);
String to = "get".equalsIgnoreCase(action) ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("user_" + to + ".jsp");
} else {//默认去列表页面
this.redirectList(request, response);
response.sendRedirect("login.jsp");
} else if ("validationCode".equalsIgnoreCase(action)) {
String codeChars = "0123456789";// 图形验证码的字符集合,系统将随机从这个字符串中选择一些字符作为验证码
// 获得验证码集合的长度
int charsLength = codeChars.length();
// 下面三条记录是关闭客户端浏览器的缓冲区
// 这三条语句都可以关闭浏览器的缓冲区,但是由于浏览器的版本不同,对这三条语句的支持也不同
// 因此,为了保险起见,建议同时使用这三条语句来关闭浏览器的缓冲区
response.setHeader("ragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
// 设置图形验证码的长和宽(图形的大小)
int width = 90, height = 20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();// 获得用于输出文字的Graphics对象
Random random = new Random();
g.setColor(getRandomColor(180, 250));// 随机设置要填充的颜色
g.fillRect(0, 0, width, height);// 填充图形背景
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();
<label class="col-sm-3 control-label">购买日期:label>
<div class="col-sm-5">
<input type="text" class="form-control" id="carIndate" name="carIndate" value="${vo.carIndate}">
div>
div>
<div class="form-group">
<label class="col-sm-3 control-label">状态:label>
<div class="col-sm-5">
正常
故障
//@Override
public void update(Car vo) {
String sql = "update `t_car` set `car_pai` = ? ,`car_name` = ? ,`car_chexing` = ? ,`car_cheng` = ? ,`car_indate` = ? ,`car_status` = ? ,`car_user` = ? ,`car_phone` = ? ,`car_text` = ? where `id` = ?";
try {
Connection c = Util.getConnection();
PreparedStatement ps = c.prepareStatement(sql);
ps.setString(1, vo.getCarPai());
ps.setString(2, vo.getCarName());
ps.setString(3, vo.getCarChexing());
ps.setString(4, vo.getCarCheng());
ps.setString(5, vo.getCarIndate());
ps.setString(6, vo.getCarStatus());
ps.setString(7, vo.getCarUser());
ps.setString(8, vo.getCarPhone());
ps.setString(9, vo.getCarText());
ps.setLong(10, vo.getId());
ps.execute();
ps.close();
c.close();
} catch (Exception e) {
e.printStackTrace();
}
userService.add(vo);
this.redirectList(request, response);
} else if ("delete".equals(action)) {//删除
//取出表要删除的用户记录的主键
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")));
vo.setUsername(Util.decode(request, "username"));
vo.setPassword(Util.decode(request, "password"));
vo.setRealName(Util.decode(request, "realName"));
vo.setUserSex(Util.decode(request, "userSex"));
vo.setUserPhone(Util.decode(request, "userPhone"));
vo.setUserText(Util.decode(request, "userText"));
vo.setUserType(Util.decode(request, "userType"));
UserService userService = new UserServiceImpl();
pb.setServlet("UserServlet");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("user_list.jsp");
}
}
package com.demo.dao.impl;
Notice vo = new Notice();
vo.setId(rs.getLong("id"));
vo.setNoticeName(rs.getString("notice_name"));
vo.setNoticeText(rs.getString("notice_text"));
vo.setNoticeType(rs.getString("notice_type"));
vo.setCreateDate(rs.getString("create_date"));
list.add(vo);
}
String sqlCount = "select count(*) from `t_notice` where 1=1 " + condition;
ps = c.prepareStatement(sqlCount);
rs = ps.executeQuery();
if (rs.next()) {
totalCount = rs.getInt(1);
}
rs.close();
ps.close();
c.close();
} catch (Exception e) {
e.printStackTrace();
}
Map<String, Object> result = new HashMap();
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) userService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("UserServlet");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("user_list.jsp");
}
}
package com.demo.dao.impl;
import com.demo.util.Util;
import com.demo.dao.CarDAO;
import com.demo.vo.Car;
return false;
}
if (document.getElementById("password").value.trim().length == 0) {
alert("密码不能为空!");
return false;
}
if (document.getElementById("realName").value.trim().length == 0) {
alert("姓名不能为空!");
return false;
}
if (document.getElementById("userPhone").value.trim().length == 0) {
alert("手机不能为空!");
return false;
}
return true;
}
script>
html>
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
import java.io.Serializable;
/**
* 车辆(t_car表对应的Java实体类)
*/
public class Car implements Serializable {
private Long id;//主键
private String carPai;//车牌
private String carName;//品牌型号
private String carChexing;//车型
private String carCheng;//里程
private String carIndate;//购买日期
private String carStatus;//状态:正常/故障
private String carUser;//驾驶员
private String carPhone;//联系方式
private String carText;//备注
public Long getId() {
return id;
return true;
}
script>
html>
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>用户编辑title>
<%@ include file="include/head.jsp" %>
head>
<body>
<div class="container-fluid">
<ul class="nav nav-tabs">
<li><a href="UserServlet?action=list">用户列表a>li>
<li class="active"><a href="#">编辑a>li>
ul>
<br/>
<form class="form-horizontal" role="form" action="UserServlet?action=edit" method="post" onsubmit="return check()">
<input type="hidden" class="form-control" id="id" name="id" value="${vo.id}"/>
<div class="form-group">
return result;
}
}
package com.demo.servlet;
import com.demo.util.Util;
import com.demo.service.NoticeService;
import com.demo.service.impl.NoticeServiceImpl;
import com.demo.vo.Notice;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
}
//@Override
public void update(Notice vo) {
String sql = "update `t_notice` set `notice_name` = ? ,`notice_text` = ? ,`notice_type` = ? ,`create_date` = ? where `id` = ?";
try {
Connection c = Util.getConnection();
PreparedStatement ps = c.prepareStatement(sql);
ps.setString(1, vo.getNoticeName());
ps.setString(2, vo.getNoticeText());
ps.setString(3, vo.getNoticeType());
ps.setString(4, vo.getCreateDate());
ps.setLong(5, vo.getId());
ps.execute();
ps.close();
c.close();
} catch (Exception e) {
e.printStackTrace();
/**
* 根据参数,查询出条例条件的记录集合,最后将数据返回给调用处或者将数据集合设置到session域里,再跳转到对应的列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = Util.decode(request, "searchColumn");
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");//根据查询条件取出对应的总记录数,用于分页
运行环境
Java≥6、Tomcat≥7.0、MySQL≥5.5
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Bootstrap
基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
登录、注册、退出、用户模块、公告模块、车辆模块的增删改查管理