欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java毕业设计实战之共享租车信息管理系统的实现

程序员文章站 2022-03-03 09:18:23
基于servlet+jsp+jdbc的后台管理系统,包含5个模块:汽车账户部管理、租车账户部管理、汽车信息管理表、租车记录表、租车租聘表。功能完整,均能实现增删查改。运行环境: jdk8+tomcat...

基于servlet+jsp+jdbc的后台管理系统,包含5个模块:汽车账户部管理、租车账户部管理、汽车信息管理表、租车记录表、租车租聘表。功能完整,均能实现增删查改。

运行环境: jdk8+tomcat8.5+mysql5.7+eclipse

项目技术: servlet+jsp+jdbc+easyui+jquery

Java毕业设计实战之共享租车信息管理系统的实现

Java毕业设计实战之共享租车信息管理系统的实现

 Java毕业设计实战之共享租车信息管理系统的实现

Java毕业设计实战之共享租车信息管理系统的实现

 Java毕业设计实战之共享租车信息管理系统的实现

 Java毕业设计实战之共享租车信息管理系统的实现

主页登陆注册业务:

public class foreservlet extends baseforeservlet {
 
    /**
     * 显示主页
     *
     * @param request
     * @param response
     * @param page
     * @return
     */
    public string home(httpservletrequest request, httpservletresponse response, page page) {
        system.out.println("调用了 foreservlet home方法");
 
        list<category> cs = new categorydao().list();
        new productdao().fill(cs);
        new productdao().fillbyrow(cs);
        request.setattribute("cs", cs);
        return "home.jsp";
    }
 
    /**
     * 注册
     *
     * @param request
     * @param response
     * @param page
     * @return
     */
    public string register(httpservletrequest request, httpservletresponse response, page page) {
        system.out.println("调用了 foreservlet register方法");
 
        map<string, string> params = new hashmap<>();
        inputstream inputstream = super.parseupload(request, params);
        system.out.println(params);
 
        string name = params.get("name");
        string password = params.get("password");
        system.out.println(name);
 
        // 判断用户名是否存在
        boolean exist = userdao.isexists(name);
        if (exist) {
            request.setattribute("msg", "用户名已经被使用");
            return "register.jsp";
        }
 
        user user = new user();
        user.setname(name);
        user.setpassword(password);
        system.out.println(user.getname());
        system.out.println(user.getpassword());
 
        userdao.add(user);
 
        return "@registersuccess.jsp";
    }
 
    /**
     * 登录
     *
     * @param request
     * @param response
     * @param page
     * @return
     */
    public string login(httpservletrequest request, httpservletresponse response, page page) {
        system.out.println("调用了 foreservlet login方法");
 
        map<string, string> params = new hashmap<>();
        inputstream inputstream = super.parseupload(request, params);
        system.out.println(params);
 
        string name = params.get("name");
        string password = params.get("password");
 
        // 登录
        user user = userdao.get(name, password);
 
        if (null == user) {
            request.setattribute("msg", "账号密码错误");
            return "login.jsp";
        }
 
        // 将账号密码储存在session中
        request.getsession().setattribute("user", user);
        return "@forehome";
    }
 
    /**
     * 登出
     *
     * @param request
     * @param response
     * @param page
     * @return
     */
    public string logout(httpservletrequest request, httpservletresponse response, page page) {
        system.out.println("调用了 foreservlet logout方法");
 
        request.getsession().removeattribute("user");
        return "@forehome";
    }
 
    /**
     * 检查用户是否登录
     *
     * @param request
     * @param response
     * @param page
     * @return
     */
    public string checklogin(httpservletrequest request, httpservletresponse response, page page) {
        user user = (user) request.getsession().getattribute("user");
        if (user != null) {
            return "%success";
        }
        return "%fail";
    }
 
    /**
     * 模态登录框通过 ajax 方法登录
     *
     * @param request
     * @param response
     * @param page
     * @return
     */
    public string loginajax(httpservletrequest request, httpservletresponse response, page page) {
        string name = request.getparameter("name");
        string password = request.getparameter("password");
 
        user user = userdao.get(name, password);
        if (user == null)
            return "%fail";
 
        request.getsession().setattribute("user", user);
        return "%success";
    }
 
    /**
     * 显示产品页
     *
     * @param request
     * @param response
     * @param page
     * @return
     */
    public string product(httpservletrequest request, httpservletresponse response, page page) {
        system.out.println("调用了 foreservlet product方法");
 
        int pid = integer.parseint(request.getparameter("pid"));
        product p = productdao.get(pid);
 
        // 获取产品的single图片和detail图片
        list<productimage> productsingleimages = productimagedao.list(p, productimagedao.type_single);
        list<productimage> productdetailimages = productimagedao.list(p, productimagedao.type_detail);
        p.setproductsingleimages(productsingleimages);
        p.setproductdetailimages(productdetailimages);
        //p.setfirstproductimage(productsingleimages.get(0));
 
        // 获取产品属性信息
        list<propertyvalue> pvs = propertyvaluedao.list(p.getid());
 
        // 获取产品评价信息
        list<review> reviews = reviewdao.list(p.getid());
 
        // 设置产品销量数和评价数
        productdao.setsaleandreviewnumber(p);
 
        request.setattribute("p", p);
        request.setattribute("pvs", pvs);
        request.setattribute("reviews", reviews);
 
        return "product.jsp";
    }
 
    /**
     * 分类页面
     *
     * @return
     */
    public string category(httpservletrequest request, httpservletresponse response, page page) {
        system.out.println("调用了foreservlet category方法");
 
        int cid = integer.parseint(request.getparameter("cid"));
 
        // 获取分类对象并为填充产品对象、销量、评价
        category c = new categorydao().get(cid);
        new productdao().fill(c);
        new productdao().setsaleandreviewnumber(c.getproducts());
 
        // 根据获取的排序方式进行排序
        string sort = request.getparameter("sort");
        if (null != sort) {
            switch (sort) {
                case "review":
                    collections.sort(c.getproducts(), new productreviewcomparator());
                    break;
                case "date":
                    collections.sort(c.getproducts(), new productdatecomparator());
                    break;
                case "salecount":
                    collections.sort(c.getproducts(), new productsalecountcomparator());
                    break;
                case "price":
                    collections.sort(c.getproducts(), new productpricecomparator());
                    break;
                case "all":
                    collections.sort(c.getproducts(), new productallcomparator());
                    break;
            }
        }
 
        // 排序完成后,将分类对象添加到域对象 request 中
        request.setattribute("c", c);
        return "category.jsp";
    }
 
    /**
     * 搜索功能
     *
     * @param request
     * @param response
     * @param page
     * @return
     */
    public string search(httpservletrequest request, httpservletresponse response, page page) {
        system.out.println("调用了foreservlet search方法");
 
        string keyword = request.getparameter("keyword");
        list<product> ps = null;
 
        // 加入异常,防止崩溃
        try {
            ps = productdao.search(keyword, 0, 50);
        } catch (exception e) {
            e.printstacktrace();
        }
 
        // 设置产品的销量和评论
        productdao.setsaleandreviewnumber(ps);
 
        request.setattribute("ps", ps);
        return "searchresult.jsp";
    }
 
    /**
     * 立即购买
     *
     * @param request
     * @param response
     * @param page
     * @return
     */
    public string buyone(httpservletrequest request, httpservletresponse response, page page) {
        system.out.println("调用了foreservlet buyone方法");
 
        int pid = integer.parseint(request.getparameter("pid"));
        int num = integer.parseint(request.getparameter("num"));
 
        product p = productdao.get(pid);
        user user = (user) request.getsession().getattribute("user");
        list<orderitem> ois = orderitemdao.listbyuser(user.getid());
 
        int oiid = 0;
        boolean found = false;
 
        // 遍历订单,如果订单已存在对应的产品,就在对应购物车的基础上调整数量
        if (null != ois) {
            for (orderitem oi : ois) {
                if (oi.getproduct().getid() == p.getid()) {
                    oi.setnumber(oi.getnumber() + num);
                    orderitemdao.update(oi);
 
                    found = true;
                    oiid = oi.getid();
                    break;
                }
            }
        }
 
        // 如果没找到对应的商品,则新建一条订单项
        if (!found) {
            orderitem oi = new orderitem();
            oi.setuser(user);
            oi.setproduct(p);
            oi.setnumber(num);
            orderitemdao.add(oi);
            oiid = oi.getid();
        }
 
        return "@forebuy?oiid=" + oiid;
    }
 
    /**
     * 结算页面
     *
     * @param request
     * @param response
     * @param page
     * @return
     */
    public string buy(httpservletrequest request, httpservletresponse response, page page) {
        system.out.println("调用了foreservlet buy方法");
 
        string[] oiids = request.getparametervalues("oiid");
        list<orderitem> ois = new arraylist<>();
        float total = 0;
 
        for (string strid : oiids) {
            int oiid = integer.parseint(strid);
            orderitem oi = orderitemdao.get(oiid);
            total += oi.getproduct().getpromoteprice() * oi.getnumber();
            ois.add(oi);
        }
 
        request.getsession().setattribute("ois", ois);
        request.setattribute("total", total);
        return "buy.jsp";
    }
 
    /**
     * 购物车
     *
     * @param request
     * @param response
     * @param page
     * @return
     */
    public string cart(httpservletrequest request, httpservletresponse response, page page) {
        system.out.println("调用了foreservlet cart方法");
 
        user user = (user) request.getsession().getattribute("user");
        list<orderitem> ois = orderitemdao.listbyuser(user.getid());
        request.setattribute("ois", ois);
        return "cart.jsp";
    }
 
    /**
     * 加入购物车
     *
     * @param request
     * @param response
     * @param page
     * @return
     */
    public string addcart(httpservletrequest request, httpservletresponse response, page page) {
        system.out.println("调用了foreservlet addcart方法");
 
        int pid = integer.parseint(request.getparameter("pid"));
        int num = integer.parseint(request.getparameter("num"));
 
        product p = productdao.get(pid);
        user user = (user) request.getsession().getattribute("user");
        list<orderitem> ois = orderitemdao.listbyuser(user.getid());
 
        int oiid = 0;
        boolean found = false;
 
        // 遍历订单,如果订单已存在对应的产品,就在对应购物车的基础上调整数量
        if (null != ois) {
            for (orderitem oi : ois) {
                if (oi.getproduct().getid() == p.getid()) {
                    oi.setnumber(oi.getnumber() + num);
                    orderitemdao.update(oi);
 
                    found = true;
                    oiid = oi.getid();
                    break;
                }
            }
        }
 
        // 如果没找到对应的商品,则新建一条订单项
        if (!found) {
            orderitem oi = new orderitem();
            oi.setuser(user);
            oi.setproduct(p);
            oi.setnumber(num);
            orderitemdao.add(oi);
            oiid = oi.getid();
        }
 
        return "%success";
    }
 
    /**
     * 更改当前订单项的内容
     *
     * @param request
     * @param response
     * @param page
     * @return
     * @throws unsupportedencodingexception
     */
    public string changeorderitem(httpservletrequest request, httpservletresponse response, page page) throws unsupportedencodingexception {
        system.out.println("调用了foreservlet changeorderitem方法");
 
        user user = (user) request.getsession().getattribute("user");
        if (null == user)
            return "%fail";
 
        int pid = integer.parseint(request.getparameter("pid"));
        int number = integer.parseint(request.getparameter("number"));
        list<orderitem> ois = orderitemdao.listbyuser(user.getid());
        for (orderitem oi : ois) {
            if (oi.getproduct().getid() == pid) {
                oi.setnumber(number);
                orderitemdao.update(oi);
                break;
            }
        }
        return "%success";
    }
 
    /**
     * 删除订单项
     *
     * @param request
     * @param response
     * @param page
     * @return
     * @throws unsupportedencodingexception
     */
    public string deleteorderitem(httpservletrequest request, httpservletresponse response, page page) throws unsupportedencodingexception {
        system.out.println("调用了foreservlet deleteorderitem方法");
 
        user user = (user) request.getsession().getattribute("user");
        if (null == user)
            return "%fail";
 
        int oiid = integer.parseint(request.getparameter("oiid"));
        orderitemdao.delete(oiid);
        return "%success";
    }
 
    /**
     * 创建订单
     *
     * @param request
     * @param response
     * @param page
     * @return
     * @throws unsupportedencodingexception
     */
    public string createorder(httpservletrequest request, httpservletresponse response, page page) throws unsupportedencodingexception {
        system.out.println("调用了foreservlet createorder方法");
 
        // 防止post方法中文乱码
        request.setcharacterencoding("utf-8");
 
        user user = (user) request.getsession().getattribute("user");
 
        list<orderitem> ois = (list<orderitem>) request.getsession().getattribute("ois");
        if (ois.isempty())
            return "@login.jsp";
 
        string address = request.getparameter("address");
        string post = request.getparameter("post");
        string reciver = request.getparameter("reciver");
        string mobile = request.getparameter("mobile");
 
        order order = new order();
        string ordercode = new simpledateformat("yyyymmddhhmmss").format(new date());
 
        order.setordercode(ordercode);
        order.setaddress(address);
        order.setpost(post);
        order.setreceiver(reciver);
        order.setmobile(mobile);
        order.setusermessage("默认内容");
        order.setcreatedate(new date());
        order.setuser(user);
        order.setstatus(orderdao.waitpay);
 
        orderdao.add(order);
 
        // 统计总金额并设置每个订单项的所属订单
        float total = 0;
        for (orderitem oi : ois) {
            oi.setorder(order);
            orderitemdao.update(oi);
 
            total += oi.getproduct().getpromoteprice() * oi.getnumber();
        }
 
        return "@forealipay?oid=" + order.getid() + "&total=" + total;
    }
 
    /**
     * 支付界面
     *
     * @param request
     * @param response
     * @param page
     * @return
     */
    public string alipay(httpservletrequest request, httpservletresponse response, page page) {
        system.out.println("调用了foreservlet alipay方法");
 
        return "alipay.jsp";
    }
 
    /**
     * 支付完成界面
     * @param request
     * @param response
     * @param page
     * @return
     */
    public string payed(httpservletrequest request, httpservletresponse response, page page) {
        system.out.println("调用了foreservlet payed方法");
 
        int oid = integer.parseint(request.getparameter("oid"));
        order order = orderdao.get(oid);
 
        order.setstatus(orderdao.waitdelivery);
        order.setpaydate(new date());
        orderdao.update(order);
 
        request.setattribute("o", order);
        return "payed.jsp";
    }
 
    /**
     * 我的订单页面
     * @param request
     * @param response
     * @param page
     * @return
     */
    public string bought(httpservletrequest request, httpservletresponse response, page page) {
        system.out.println("调用了foreservlet bought方法");
 
        user user = (user) request.getsession().getattribute("user");
        list<order> os = orderdao.list(user.getid(), orderdao.delete);
 
        orderitemdao.fill(os);
 
        request.setattribute("os", os);
        return "bought.jsp";
    }
 
 
 
}

用户登陆页面:

<%@ page contenttype="text/html;charset=utf-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
 
<!doctype html>
<html>
<head>
	<title>用户登录</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="content-type" content="text/html; charset=utf-8">
	<link type="text/css" rel="stylesheet" href="<%=request.getcontextpath()%>/css/bootstrap.css" rel="external nofollow" >
	<link type="text/css" rel="stylesheet" href="<%=request.getcontextpath()%>/css/style.css" rel="external nofollow" >
	<script type="text/javascript" src="<%=request.getcontextpath()%>/js/jquery.min.js"></script>
	<script type="text/javascript" src="<%=request.getcontextpath()%>/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="<%=request.getcontextpath()%>/js/simplecart.min.js"></script>
</head>
<body>
 
	
 
 
 
 
 
	<!--header-->
	<jsp:include page="header.jsp">
		<jsp:param name="flag" value="9"></jsp:param>
	</jsp:include>
	<!--//header-->
 
	
	<!--account-->
	<div class="account">
		<div class="container">
			<div class="register">
				<c:if test="${!empty msg }">
					<div class="alert alert-success">${msg }</div>
				</c:if>
				<c:if test="${!empty failmsg }">
					<div class="alert alert-danger">${failmsg }</div>
				</c:if>
 
				<form action="<%=request.getcontextpath()%>/user_login" method="post">
					<div class="register-top-grid">
						<h3>用户登录</h3>
						<div class="input">
							<span>用户名/邮箱 <label style="color:red;">*</label></span>
							<input type="text" name="ue" placeholder="请输入用户名" required="required">
						</div>
						<div class="input">
							<span>密码 <label style="color:red;">*</label></span>
							<input type="text" name="password" placeholder="请输入密码" required="required">
						</div>
 
						<div class="clearfix"> </div>
					</div>
					<div class="register-but text-center">
						<input type="submit" value="提交">
						<div class="clearfix"> </div>
					</div>
				</form>
				<div class="clearfix"> </div>
			</div>
	    </div>
	</div>
	<!--//account-->
 
	
 
 
 
 
	<!--footer-->
	<jsp:include page="footer.jsp"></jsp:include>
	<!--//footer-->
 
	
</body>
</html>

添加类型业务:

@webservlet("/addcategoryservlet")
public class addcategoryservlet extends httpservlet {
    protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
        request.setcharacterencoding("utf-8");
        response.setcharacterencoding("utf-8");
        string a = request.getparameter("parentid");
        string b = request.getparameter("classname");
 
        system.out.println("parentid"+a);
        system.out.println("classname"+b);
 
        category category = new category();
        category.setcategory_parentid(integer.valueof(a));
        category.setcategory_name(b);
 
        categoryservice service = new categoryserviceimpl();
        service.addcategory(category);
 
        printwriter out = response.getwriter();
        out.write("<script>");
        out.write("alert('插入分类成功!');");
        out.write("location.href='/homeecms/categorylistservlet'");
        out.write("</script>");
        out.close();
 
//        request.getrequestdispatcher("").forward(request,response);
    }
 
    protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
        dopost(request,response);
    }
}

到此这篇关于java毕业设计实战之共享租车信息管理系统的实现的文章就介绍到这了,更多相关java 共享租车信息管理内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!