基于javaweb+mysql的jsp+servlet租车服务系统(java+servlet+jsp+jdbc+mysql)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的JSP+Servlet租车服务系统(java+servlet+jsp+jdbc+mysql)
项目介绍
系统基于租车业务场景而搭建的O2O服务平台,可为用户提供商务租车、接送机、旅游租车、企业租车、自驾租车、婚庆用车等自助租车服务。
系统根据相关版本提供相关内容服务。包含车辆库管理、司机管理、订单管理、活动管理、评价管理等。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目: 否;
技术栈
Servlet、JSP、JDBC、MySQL5.7、Tomcat8
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,然后运行; 3. 将项目中src/com/dao/DB.java配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入地址; 前台访问地址:http://localhost:8080/opencar/ 后台访问地址:http://localhost:8080/opencar/admin/login 管理员账号/密码:admin/zft3285497
doGet( request, response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
@WebServlet(displayName="获取外部员工的信息",name="AuntList",urlPatterns="/aunt")
public class AuntList extends HttpServlet{
private static final long serialVersionUID = 1L;
/**
* Constructor of the object.
*/
public AuntList() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
}else{
json="{\"tip\":\"订单取消失败\"}";
}
}else{
json="{\"tip\":\"此单并非您的单,您不能做次操作\"}";
}
out.print(json);
out.flush();
out.close();
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
*/
public void init() throws ServletException {
// Put your code here
}
}
@WebServlet(displayName="用户中心",name="PcUserIndex",urlPatterns="/pc/pcUserIndex")
public class PcUserIndex extends HttpServlet {
/**
* Constructor of the object.
*/
public PcUserIndex() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet( request, response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
json="\"扣费失败,用户的金额小于要扣除的金额\"";
}else{
String flag="";
//String flag=ms.updateUserMoney(user.getTel(),active.getPrice(),"reduce");
String timeStr=StringUtil.getTimeStr();
String nowStr[]=timeStr.split("-");
if(flag.equals("ok")){
ss.updateplayFlag(order_id, 1);
//ms.addRechargeRecord(user.getId(), 2, 1, user.getCard(), active.getPrice(), Integer.parseInt(nowStr[0]), Integer.parseInt(nowStr[1]), Integer.parseInt(nowStr[2]),1,0,null,order_id);
json="\"扣费成功,您账户上面减少了“"+active.getPrice()+"元”\"";
}else{
json="\"扣费失败,系统发生未知错误\"";
}
}
request.setAttribute("tip",json);
ReturnJspUrl reJsp=new ReturnJspUrl();
String jsp=reJsp.url(request,"page/tip.jsp");
RequestDispatcher rd = request.getRequestDispatcher(jsp);
rd.forward(request,response);
}
}
/**
* 获取订单的全部服务
*/
public void getGoodsTypeByActive(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException{
response.setContentType("text/html;charset=UTF-8");
HttpSession session = request.getSession(true);
ShopService ss=new ShopService();
Object ordinary_user=session.getAttribute("ordinary_user");
if(ordinary_user==null){//非登陆用户
RequestDispatcher rd = request.getRequestDispatcher("/template/default/page/user_login.jsp");
rd.forward(request,response);
}else{//登陆用户
String tem_order_id=request.getParameter("order_id");
Integer order_id=0;
if(tem_order_id!=null && !tem_order_id.equals("")){
order_id=Integer.parseInt(tem_order_id);
}
List<GoodsPojo> goodsList=null;
try {
goodsList=ss.getGoodsPojoByOrder(order_id);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ReturnJspUrl reJsp=new ReturnJspUrl();
String jsp=reJsp.url(request,"page/user/order_all_goods.jsp");
request.setAttribute("goodsList",goodsList);
@WebServlet(displayName = "前端基本信息", name = "FrontAction", urlPatterns = "/front")
public class FrontAction extends AbstractServlet {
private static final long serialVersionUID = 1L;
ShopService ss = new ShopService();
AdminService as = new AdminService();
UserService us = new UserService();
CategoryService cs = new CategoryService();
GetNoCmsService ps = new GetNoCmsService();
/**
* 获取商品详情
*
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void goodsDetail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String jsp = "";
Template tpl = null;
String tem_id = request.getParameter("id");
Integer id = 0;
if (tem_id != null && !tem_id.equals("")) {
id = Integer.parseInt(tem_id);
}
GoodsPojo goods = null;
try {
tpl = us.getTemplate();
goods = ss.getGoodsPojoById(id);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setAttribute("goods", goods);
if (goods.getCategory().getId().equals(17)) {
request.setAttribute("special", "x");
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet( request, response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
@WebServlet(displayName="跳转到添加用户地址信息",name="PcUserAddAddress",urlPatterns="/pc/pcUserAddAddress")
public class PcUserAddAddress extends HttpServlet {
/**
* Constructor of the object.
*/
public PcUserAddAddress() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
*/
public GoodsList() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
UserService us=new UserService();
ShopService ss=new ShopService();
ReturnJspUrl rj=new ReturnJspUrl();
String menuId=request.getParameter("menuId");//获取菜单id
Recept recept=null;
String jsp="";
try {
List<GoodsPojo> goodsList=null;
List<GoodsPojo> goodsList2=null;
String pageNoTem=request.getParameter("page") ;
Integer sum=0;
Integer pageNo=0;
if(pageNoTem!=null){
pageNo=Integer.parseInt(pageNoTem);
}else{
pageNo=1;
}
String pageSizeTem=CommonUrl.getValue("user_page");
Integer pageSize=Integer.parseInt(pageSizeTem);
String tem_type_id=request.getParameter("type_id");
String tem_brand_id=request.getParameter("brand_id");
String tem_cat_id=request.getParameter("cat_id");
String tem_price=request.getParameter("price");
String order=request.getParameter("order");
String price="x";
if(tem_price!=null && !tem_price.equals("")){
price=tem_price;
}
if(tem_cat_id==null||tem_cat_id.equals("")){
request.setAttribute("active",active);
ReturnJspUrl reJsp=new ReturnJspUrl();
String jsp=reJsp.url(request,"page/user/add_active_two.jsp");
RequestDispatcher rd = request.getRequestDispatcher(jsp);
rd.forward(request,response);
}
}
/**
* 确认订单信息
*/
public void addActiveThree(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException{
response.setContentType("text/html;charset=UTF-8");
HttpSession session = request.getSession(true);
ShopService ss=new ShopService();
Object ordinary_user=session.getAttribute("ordinary_user");
if(ordinary_user==null){//非登陆用户
RequestDispatcher rd = request.getRequestDispatcher("/template/default/page/login.jsp");
rd.forward(request,response);
}else{//登陆用户
String json="";
//MyService ms=new MyService();
Active active=null;
String active_id=request.getParameter("active_id");
String address_id=request.getParameter("address_id");
String starttime=request.getParameter("starttime");
String endtime=request.getParameter("endtime");
Integer order_id=null;
List<GoodsType> typeList=null;
// try {
// active=ss.getActivebyId(active_id);
// typeList = ss.getGoodsTypeForActive(active_id);
// } catch (SQLException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
User user=(User)ordinary_user;
//order_id= ss.addGoodsOrder(3,1,1, 0, starttime, endtime, "", user.getId(),null,null,null, active.getPrice(),2, 0, Integer.parseInt(address_id),1,"3",user.getName(),user.getId(),typeList.get(0).getId(),1,"");
for(int i=0;i<typeList.size();i++){
//ss.addServerAndOrder(typeList.get(i).getId().toString(),order_id.toString());
}
if(Double.parseDouble(active.getPrice())>user.getMoney()){//自己的钱少于扣费金额
json="\"扣费失败,用户的金额小于要扣除的金额\"";
}else{
String flag="";
//String flag=ms.updateUserMoney(user.getTel(),active.getPrice(),"reduce");
String timeStr=StringUtil.getTimeStr();
String nowStr[]=timeStr.split("-");
if(flag.equals("ok")){
pageNo=Integer.parseInt(pageNoTem);
}else{
pageNo=1;
}
String pageSizeTem=CommonUrl.getValue("user_page");
Integer pageSize=Integer.parseInt(pageSizeTem);
activityList=ss.goThematicActivity(pageNo, pageSize,2,StringUtil.getTimeStr());
sum=ss.goThematicActivityCount(2, StringUtil.getTimeStr());
recept=us.getReceptById(menuId);
request.setAttribute("recept",recept);
request.setAttribute("menuId",menuId);
request.setAttribute("pageNo",pageNo);
request.setAttribute("activityList",activityList);
if(sum%pageSize==0){
request.setAttribute("sum",sum/pageSize);
}else{
request.setAttribute("sum",sum/pageSize+1);
}
jsp=rj.url(request, "/page/"+recept.getJspMod()+".jsp");
RequestDispatcher rd = request.getRequestDispatcher(jsp);
rd.forward(request,response);
} catch (NumberFormatException e) {
jsp= "/404.jsp";//前台的手机jsp页面
RequestDispatcher rd = request.getRequestDispatcher(jsp);
rd.forward(request,response);
}catch (SQLException e) {
jsp= "/404.jsp";//前台的手机jsp页面
RequestDispatcher rd = request.getRequestDispatcher(jsp);
rd.forward(request,response);
}catch (NullPointerException e) {
jsp= "/404.jsp";//前台的手机jsp页面
RequestDispatcher rd = request.getRequestDispatcher(jsp);
rd.forward(request,response);
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
HttpSession session = request.getSession(true);
ShopService ss=new ShopService();
Object ordinary_user=session.getAttribute("ordinary_user");
if(ordinary_user==null){//非登陆用户
RequestDispatcher rd = request.getRequestDispatcher("/template/default/page/login.jsp");
rd.forward(request,response);
}else{//登陆用户
User user=null;
user=(User)ordinary_user;
String active_id=request.getParameter("active_id");
List<GoodsType> typeList=null;
Active active=null;
List<Address> addressList=null;
try {
// typeList = ss.getGoodsTypeForActive(active_id);
// active=ss.getActivebyId(active_id);
addressList=ss.getAddressByUser(user.getId());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ReturnJspUrl reJsp=new ReturnJspUrl();
String jsp=reJsp.url(request,"page/user/add_active.jsp");
request.setAttribute("typeList",typeList);
request.setAttribute("active",active);
request.setAttribute("addressList",addressList);
RequestDispatcher rd = request.getRequestDispatcher(jsp);
rd.forward(request,response);
}
}
/**
* 活动订单确认信息
*/
public void addActiveTwo(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException{
response.setContentType("text/html;charset=UTF-8");
HttpSession session = request.getSession(true);
ShopService ss=new ShopService();
Object ordinary_user=session.getAttribute("ordinary_user");
if(ordinary_user==null){//非登陆用户
RequestDispatcher rd = request.getRequestDispatcher("/template/default/page/login.jsp");
rd.forward(request,response);
*/
public ThematicList() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
UserService us=new UserService();
ShopService ss=new ShopService();
ReturnJspUrl rj=new ReturnJspUrl();
String menuId=request.getParameter("menuId");//获取菜单id
Recept recept=null;
String jsp="";
try {
List<ThematicActivity> activityList=null;
String pageNoTem=request.getParameter("page") ;
Integer sum=0;
Integer pageNo=0;
if(pageNoTem!=null){
pageNo=Integer.parseInt(pageNoTem);
}else{
pageNo=1;
}
String pageSizeTem=CommonUrl.getValue("user_page");
Integer pageSize=Integer.parseInt(pageSizeTem);
activityList=ss.goThematicActivity(pageNo, pageSize,2,StringUtil.getTimeStr());
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
UserService us=new UserService();
ShopService ss=new ShopService();
ReturnJspUrl rj=new ReturnJspUrl();
String menuId=request.getParameter("menuId");//获取菜单id
Recept recept=null;
String jsp="";
try {
List<GoodsPojo> goodsList=null;
List<GoodsPojo> goodsList2=null;
String pageNoTem=request.getParameter("page") ;
Integer sum=0;
Integer pageNo=0;
if(pageNoTem!=null){
pageNo=Integer.parseInt(pageNoTem);
}else{
pageNo=1;
}
String pageSizeTem=CommonUrl.getValue("user_page");
Integer pageSize=Integer.parseInt(pageSizeTem);
String tem_type_id=request.getParameter("type_id");
String tem_brand_id=request.getParameter("brand_id");
String tem_cat_id=request.getParameter("cat_id");
String tem_price=request.getParameter("price");
String order=request.getParameter("order");
String price="x";
if(tem_price!=null && !tem_price.equals("")){
price=tem_price;
}
if(tem_cat_id==null||tem_cat_id.equals("")){
tem_cat_id="1";
}
if(tem_type_id==null||tem_type_id.equals("")){
tem_type_id="";
}else{
String type_id[]=tem_type_id.split(",");
StringUtil su=new StringUtil();
tem_type_id=su.arrayToString(type_id);
}
if(tem_brand_id==null||tem_brand_id.equals("")){
tem_brand_id="";
}else{
String brand_id[]=tem_brand_id.split(",");
StringUtil su=new StringUtil();
tem_brand_id=su.arrayToString(brand_id);
}
goodsList=ss.getGoodsPojoListByTypeAndcatAndBranAndPrice(pageNo, pageSize, tem_cat_id, tem_type_id, tem_brand_id, price, order);
sum=ss.getGoodsPojoListByTypeAndcatAndBranAndPriceCount(tem_cat_id, tem_type_id, tem_brand_id, price);
try {
goodsList2=ss.getGoodsListByExtendCat(pageNo, pageSize-goodsList.size(),tem_cat_id,tem_type_id,tem_brand_id,price);
} catch (SQLException e) {
String jsp="";
String pageNoTem=request.getParameter("page") ;
Integer pageNo=0;
if(pageNoTem!=null){
pageNo=Integer.parseInt(pageNoTem);
}else{
pageNo=1;
}
String pageSizeTem=CommonUrl.getValue("user_page");
Integer pageSize=Integer.parseInt(pageSizeTem);
Integer sum=0;
try {
List<CombineMarket> marketList=null;
marketList=ss.getCombineMarketList(pageNo, pageSize,2,StringUtil.getTimeStr());
sum=ss.getCombineMarketCount(2,StringUtil.getTimeStr());
recept=us.getReceptById(menuId);
request.setAttribute("recept",recept);
request.setAttribute("menuId",menuId);
request.setAttribute("marketList",marketList);
request.setAttribute("pageNo",pageNo);
if(sum%pageSize==0){
request.setAttribute("sum",sum/pageSize);
}else{
request.setAttribute("sum",sum/pageSize+1);
}
jsp=rj.url(request, "/page/"+recept.getJspMod()+".jsp");
RequestDispatcher rd = request.getRequestDispatcher(jsp);
rd.forward(request,response);
} catch (NumberFormatException e) {
jsp= "/404.jsp";//前台的手机jsp页面
RequestDispatcher rd = request.getRequestDispatcher(jsp);
rd.forward(request,response);
}catch (SQLException e) {
jsp= "/404.jsp";//前台的手机jsp页面
RequestDispatcher rd = request.getRequestDispatcher(jsp);
rd.forward(request,response);
}catch (NullPointerException e) {
jsp= "/404.jsp";//前台的手机jsp页面
RequestDispatcher rd = request.getRequestDispatcher(jsp);
rd.forward(request,response);
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
if(go.getUser_id().equals(user.getId())){//自己才能取消订单
flag=ss.updateOrderFlag(Integer.parseInt(order_id),4);
List<OrderMoneyRecord> moneyList=null;
try {
moneyList = ss.getOrderMoneyRecordByOrderId(Integer.parseInt(order_id));
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Double money=0.0;
for(int i=0;i<moneyList.size();i++){
OrderMoneyRecord record=moneyList.get(i);
if(record.getFlag().equals(1) && !record.getSource().equals(6) && !record.getSource().equals(7)){
money+=Double.parseDouble(record.getMoney());
ss.updateuserCardFlag(record.getId(),2);
}
}
String timeStr=StringUtil.getTimeStr();
String nowStr[]=timeStr.split("-");
ss.updateUserMoney(user.getId(),money);
ss.addRechargeRecord(user.getId(),3, 1, user.getCard(), money.toString(), Integer.parseInt(nowStr[0]), Integer.parseInt(nowStr[1]), Integer.parseInt(nowStr[2]),2,null,null,0,1);
if(flag.equals("ok")){
json="{\"tip\":\"订单取消成功\"}";
}else{
json="{\"tip\":\"订单取消失败\"}";
}
}else{
json="{\"tip\":\"此单并非您的单,您不能做次操作\"}";
}
out.print(json);
out.flush();
out.close();
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
HttpSession session = request.getSession(true);
Object ordinary_user= session.getAttribute("ordinary_user");
if(ordinary_user==null){
RequestDispatcher rd = request.getRequestDispatcher("/template/default/page/login.jsp");
rd.forward(request,response);
}else{
User user=(User)ordinary_user;
ShopService ss=new ShopService();
String goodsTypeFlag=request.getParameter("goodsTypeFlag");
String goodsTypeId=request.getParameter("goodsTypeId");
String orderPrice=request.getParameter("orderPrice");
String gradeName=request.getParameter("gradeName");
String address_id=request.getParameter("address_id");
String starttime=request.getParameter("starttime");
String endtime=request.getParameter("endtime");
String desc=request.getParameter("desc");
Address address=null;
GoodsType goodsType=null;
Integer myMoneyFlag=0;
try {
address=ss.getAddressById(Integer.parseInt(address_id));
goodsType=ss.getGoodsTypeById(Integer.parseInt(goodsTypeId));
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(goodsTypeFlag.equals("2")){
if(user.getMoney()>Double.parseDouble(orderPrice)){
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}