基于javaweb+mysql的jsp+servlet停车位预定管理系统(java+jsp+javascript+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet停车位预定管理系统(java+jsp+javascript+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版本;
技术栈
HTML+CSS+JavaScript+jsp+mysql
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application.yml配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/login.jsp 登录
public class yuding_servlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
{
String type=req.getParameter("type");
if(type.endsWith("yudingAdd"))
{
yudingAdd(req, res);
}
if(type.endsWith("yudingMine"))
{
yudingMine(req, res);
}
if(type.endsWith("yudingDel"))
{
yudingDel(req, res);
}
if(type.endsWith("yudingMana"))
{
yudingMana(req, res);
}
if(type.endsWith("yudingShouli"))
{
yudingShouli(req, res);
}
}
public void yudingAdd(HttpServletRequest req,HttpServletResponse res)
{
HttpSession session=req.getSession();
Tuser user=(Tuser)session.getAttribute("user");
String id=String.valueOf(new Date().getTime());
String xingming=req.getParameter("xingming");
String dianhua=req.getParameter("dianhua");
String daodashi=req.getParameter("daodashi");
int chewei_id=Integer.parseInt(req.getParameter("chewei_id"));
String user_id=user.getId();
String zt="待受理";
String neirong=req.getParameter("neirong");
String liuyanshi=new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date());
String user_id=user.getId();
String huifu="";
String huifushi="";
String sql="insert into t_liuyan(neirong,liuyanshi,user_id,huifu,huifushi) values(?,?,?,?,?)";
Object[] params={neirong,liuyanshi,user_id,huifu,huifushi};
DB mydb=new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("msg", "留言完毕");
String targetURL = "/common/msg.jsp";
dispatch(targetURL, req, res);
}
public void liuyanMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
List liuyanList=new ArrayList();
String sql="select * from t_liuyan order by liuyanshi";
Object[] params={};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
while(rs.next())
{
TLiuyan liuyan=new TLiuyan();
liuyan.setId(rs.getInt("id"));
liuyan.setNeirong(rs.getString("neirong"));
liuyan.setLiuyanshi(rs.getString("liuyanshi"));
liuyan.setUser_id(rs.getString("user_id"));
liuyan.setHuifu(rs.getString("huifu"));
liuyan.setHuifushi(rs.getString("huifushi"));
liuyanList.add(liuyan);
}
rs.close();
}
catch(Exception e)
{
}
else
{
result="yes";
TAdmin admin=new TAdmin();
admin.setUserId(rs.getInt("userId"));
admin.setUserName(rs.getString("userName"));
admin.setUserPw(rs.getString("userPw"));
session.setAttribute("userType", 0);
session.setAttribute("admin", admin);
}
rs.close();
}
catch (SQLException e)
{
System.out.println("登录失败!");
e.printStackTrace();
}
finally
{
mydb.closed();
}
}
if(userType==1)
{
String sql="select * from t_user where loginname=? and loginpw=? and del='no'";
Object[] params={userName,userPw};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
boolean mark=(rs==null||!rs.next()?false:true);
if(mark==false)
{
result="no";
}
if(mark==true)
{
result="yes";
public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response)
{
RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
try
{
dispatch.forward(request, response);
return;
}
catch (ServletException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void destroy()
{
}
}
public class chewei_servlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
{
String type=req.getParameter("type");
if(type.endsWith("cheweiMana"))
e.printStackTrace();
}
mydb.closed();
req.setAttribute("cheweiList", cheweiList);
req.getRequestDispatcher("qiantai/chewei/cheweiRes.jsp").forward(req, res);
}
public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response)
{
RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
try
{
dispatch.forward(request, response);
return;
}
catch (ServletException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void destroy()
{
}
}
WebContext ctx = WebContextFactory.get();
HttpSession session=ctx.getSession();
String result="no";
if(userType==0)//系统管理员登陆
{
String sql="select * from t_admin where userName=? and userPw=?";
Object[] params={userName,userPw};
DB mydb=new DB();
mydb.doPstm(sql, params);
try
{
ResultSet rs=mydb.getRs();
boolean mark=(rs==null||!rs.next()?false:true);
if(mark==false)
{
result="no";
}
else
{
result="yes";
TAdmin admin=new TAdmin();
admin.setUserId(rs.getInt("userId"));
admin.setUserName(rs.getString("userName"));
admin.setUserPw(rs.getString("userPw"));
session.setAttribute("userType", 0);
session.setAttribute("admin", admin);
}
rs.close();
}
catch (SQLException e)
{
System.out.println("登录失败!");
e.printStackTrace();
}
finally
{
mydb.closed();
}
}
if(userType==1)
{
int beishu=1;
int zong=0;
if(chexing.equals("小型"))
{
beishu=1;
}
if(chexing.equals("中型"))
{
beishu=2;
}
if(chexing.equals("大型"))
{
beishu=3;
}
Date aa=Util.newDate1(kaishishijian);
Date bb=Util.newDate1(jieshushijian);
long gg=bb.getTime()-aa.getTime();
long fenzhong=gg/1000/60;
if(fenzhong<60)
{
zong=danjia * 1 * beishu;
}
if(fenzhong>60 && fenzhong<120)
{
zong=danjia * 2 * beishu;
}
if(fenzhong>120 && fenzhong<180)
{
zong=danjia * 3 * beishu;
}
if(fenzhong>180 && fenzhong<240)
{
zong=danjia * 4 * beishu;
}
if(fenzhong>240 && fenzhong<300)
{
zong=danjia * 5 * beishu;
}
if(fenzhong>300 && fenzhong<360)
{
zong=danjia * 6 * beishu;
}
if(fenzhong>360 && fenzhong<420)
{
catch(Exception e)
{
e.printStackTrace();
}
mydb.closed();
req.setAttribute("zhengceList", zhengceList);
req.getRequestDispatcher("admin/zhengce/zhengceMana.jsp").forward(req, res);
}
public void zhengceDel(HttpServletRequest req,HttpServletResponse res)
{
String id=req.getParameter("id");
String sql="delete from t_zhengce where id=?";
Object[] params={id};
DB mydb=new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("msg", "操作成功");
String targetURL = "/common/msg.jsp";
dispatch(targetURL, req, res);
}
public void zhengceDetailHou(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
String id=req.getParameter("id");
TZhengce zhengce=new TZhengce();
String sql="select * from t_zhengce where id=?";
Object[] params={id};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
rs.next();
return "yes";
}
public int jisuanfeiyong(String kaishishijian,String jieshushijian,String chexing) throws Exception
{
String s="入场时间:"+kaishishijian+",出场时间:"+jieshushijian+",车型:"+chexing;
System.out.println(s);
//收费标准:小型1元/小时、中型2元/小时,大型3元/小时,不足一小时按照一小时计算
int danjia=1;
int beishu=1;
int zong=0;
if(chexing.equals("小型"))
{
beishu=1;
}
if(chexing.equals("中型"))
{
beishu=2;
}
if(chexing.equals("大型"))
{
beishu=3;
}
Date aa=Util.newDate1(kaishishijian);
Date bb=Util.newDate1(jieshushijian);
long gg=bb.getTime()-aa.getTime();
long fenzhong=gg/1000/60;
if(fenzhong<60)
{
zong=danjia * 1 * beishu;
}
if(fenzhong>60 && fenzhong<120)
{
zong=danjia * 2 * beishu;
}
if(fenzhong>120 && fenzhong<180)
{
zong=danjia * 3 * beishu;
}
if(fenzhong>180 && fenzhong<240)
{
zong=danjia * 4 * beishu;
}
}
public String adminPwEdit(String userPwNew)
{
System.out.println("DDDD");
try
{
Thread.sleep(700);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
WebContext ctx = WebContextFactory.get();
HttpSession session=ctx.getSession();
TAdmin admin=(TAdmin)session.getAttribute("admin");
String sql="update t_admin set userPw=? where userId=?";
Object[] params={userPwNew,admin.getUserId()};
DB mydb=new DB();
mydb.doPstm(sql, params);
return "yes";
}
public int jisuanfeiyong(String kaishishijian,String jieshushijian,String chexing) throws Exception
{
String s="入场时间:"+kaishishijian+",出场时间:"+jieshushijian+",车型:"+chexing;
System.out.println(s);
//收费标准:小型1元/小时、中型2元/小时,大型3元/小时,不足一小时按照一小时计算
int danjia=1;
int beishu=1;
int zong=0;
if(chexing.equals("小型"))
{
beishu=1;
}
if(chexing.equals("中型"))
{
beishu=2;
}
if(chexing.equals("大型"))
{
beishu=3;
}
if(userType==1)
{
String sql="select * from t_user where loginname=? and loginpw=? and del='no'";
Object[] params={userName,userPw};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
boolean mark=(rs==null||!rs.next()?false:true);
if(mark==false)
{
result="no";
}
if(mark==true)
{
result="yes";
Tuser user=new Tuser();
user.setId(rs.getString("id"));
user.setLoginname(rs.getString("loginname"));
user.setLoginpw(rs.getString("loginpw"));
user.setXingming(rs.getString("xingming"));
user.setZhuzhi(rs.getString("zhuzhi"));
user.setDianhua(rs.getString("dianhua"));
user.setDengji(rs.getString("dengji"));
user.setDel(rs.getString("del"));
session.setAttribute("userType", 1);
session.setAttribute("user", user);
}
rs.close();
}
public void tingMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
List tingList=new ArrayList();
String sql="select * from t_ting order by id desc";
Object[] params={};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
while(rs.next())
{
Tting ting=new Tting();
ting.setId(rs.getInt("id"));
ting.setChewei_id(rs.getInt("chewei_id"));
ting.setChexing(rs.getString("chexing"));
ting.setChepai(rs.getString("chepai"));
ting.setKaishishijian(rs.getString("kaishishijian"));
ting.setJieshushijian(rs.getString("jieshushijian"));
ting.setFeiyong(rs.getInt("feiyong"));
ting.setChewei(liuService.get_chewei(rs.getInt("chewei_id")));
tingList.add(ting);
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb.closed();
req.setAttribute("tingList", tingList);
req.getRequestDispatcher("admin/ting/tingMana.jsp").forward(req, res);
}
public void tingDel(HttpServletRequest req,HttpServletResponse res)
{
int chewei_id=Integer.parseInt(req.getParameter("chewei_id"));
int id=Integer.parseInt(req.getParameter("id"));
String sql="delete from t_ting where id=?";
Object[] params={id};
DB mydb=new DB();
mydb.doPstm(sql, params);
mydb.closed();
{
e.printStackTrace();
}
}
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void destroy()
{
}
}
public class loginService
{
public String login(String userName,String userPw,int userType)
{
System.out.println(userType+"UUU");
WebContext ctx = WebContextFactory.get();
HttpSession session=ctx.getSession();
public class zhengce_servlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
{
String type=req.getParameter("type");
if(type.endsWith("zhengceAdd"))
{
zhengceAdd(req, res);
}
if(type.endsWith("zhengceMana"))
{
zhengceMana(req, res);
}
if(type.endsWith("zhengceDel"))
{
zhengceDel(req, res);
}
if(type.endsWith("zhengceDetailHou"))
{
zhengceDetailHou(req, res);
}
if(type.endsWith("zhengceAll"))
{
zhengceAll(req, res);
}
if(type.endsWith("zhengceDetailQian"))
{
zhengceDetailQian(req, res);
}
}
public void zhengceAdd(HttpServletRequest req,HttpServletResponse res)
{
String id=String.valueOf(new Date().getTime());
String biaoti=req.getParameter("biaoti");
String neirong=req.getParameter("neirong");
String fujian=req.getParameter("fujian");
String sql="select * from t_zhengce";
Object[] params={};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
while(rs.next())
{
TZhengce zhengce=new TZhengce();
zhengce.setId(rs.getString("id"));
zhengce.setBiaoti(rs.getString("biaoti"));
zhengce.setNeirong(rs.getString("neirong"));
zhengce.setFujian(rs.getString("fujian"));
zhengce.setShijian(rs.getString("shijian"));
zhengceList.add(zhengce);
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb.closed();
req.setAttribute("zhengceList", zhengceList);
req.getRequestDispatcher("qiantai/zhengce/zhengceAll.jsp").forward(req, res);
}
public void zhengceDetailQian(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
String id=req.getParameter("id");
TZhengce zhengce=new TZhengce();
String sql="select * from t_zhengce where id=?";
Object[] params={id};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
rs.next();
zhengce.setId(rs.getString("id"));
zhengce.setBiaoti(rs.getString("biaoti"));
user.setDianhua(rs.getString("dianhua"));
user.setDengji(rs.getString("dengji"));
user.setDel(rs.getString("del"));
session.setAttribute("userType", 1);
session.setAttribute("user", user);
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb.closed();
return result;
}
public String adminPwEdit(String userPwNew)
{
System.out.println("DDDD");
try
{
Thread.sleep(700);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
WebContext ctx = WebContextFactory.get();
HttpSession session=ctx.getSession();
TAdmin admin=(TAdmin)session.getAttribute("admin");
String sql="update t_admin set userPw=? where userId=?";
Object[] params={userPwNew,admin.getUserId()};
DB mydb=new DB();
mydb.doPstm(sql, params);
return "yes";
}
public class yuding_servlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
{
String type=req.getParameter("type");
if(type.endsWith("yudingAdd"))
{
yudingAdd(req, res);
}
if(type.endsWith("yudingMine"))
{
yudingMine(req, res);
}
if(type.endsWith("yudingDel"))
{
yudingDel(req, res);
}
if(type.endsWith("yudingMana"))
{
yudingMana(req, res);
}
if(type.endsWith("yudingShouli"))
{
yudingShouli(req, res);
}
}
public void yudingAdd(HttpServletRequest req,HttpServletResponse res)
{