购物车2.0版本(连接数据库)

首先是登录页面login.jsp

购物车2.0版本(连接数据库)_第1张图片

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>




用户登录





	
用 户
密 码
验证码
版本信息 管理信息系统 2008 v2.0

将账号密码传到dologin.jsp连接数据库中用户表判断账号密码是否正确

<%@page import="com.zking.entity.User"%>
<%@page import="com.zking.biz.imp.Imp_Userbiz"%>
<%@page import="com.zking.biz.IUserbiz"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
//乱码
	request.setCharacterEncoding("utf-8");
	String uname = request.getParameter("textfield");
	String jks=request.getParameter("jk");
	int jk=0;
	String upwd = request.getParameter("textfield2");
	IUserbiz iub=new Imp_Userbiz();
	User u=iub.login(uname, upwd);
	if(u!=null){//成功就跳转到主页面
			session.setAttribute("a", u.getUid());
			request.getRequestDispatcher("index.jsp").forward(request, response);
	}else{//错误就回到登录页面
			out.print("");
		}
%>

登录成功后就会进入到index.jsp商品页面

购物车2.0版本(连接数据库)_第2张图片

点击添加到购物车就会把商品的编号传到dogwc.jsp,在dogwc.jsp中进行添加至数据库订单表 

<%@page import="com.zking.util.DBHelper"%>
<%@page import="com.zking.entity.OrderItem"%>
<%@page import="com.zking.biz.imp.Imp_orderItembiz"%>
<%@page import="com.zking.biz.IorderItembiz"%>
<%@page import="com.zking.biz.imp.Imp_Goodsbiz"%>
<%@page import="com.zking.dao.imp.Imp_GoodsDao"%>
<%@page import="com.zking.biz.IGoodsbiz"%>
<%@page import="com.zking.entity.Goods"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>




Insert title here






	
		<%
		IGoodsbiz igb=new Imp_Goodsbiz();
		ArrayList glist=igb.getAll();
		for(Goods g :glist){
			//System.out.print(g);
		%>
		
		<%}%>
	
商品编号 商品名称 商品单价 商品介绍 商品图片 操作一下
<%=g.getBid()%> <%=g.getBname()%> <%=g.getBprice()%> <%=g.getBinfo()%>

dogwc.jsp把商品添加到订单表

<%@page import="org.eclipse.jdt.internal.compiler.batch.Main"%>
<%@page import="com.zking.biz.imp.Imp_orderItembiz"%>
<%@page import="com.zking.biz.IorderItembiz"%>
<%@page import="com.zking.util.DBHelper"%>
<%@page import="com.zking.entity.Goods"%>
<%@page import="org.apache.catalina.util.Introspection"%>
<%@page import="com.zking.biz.imp.Imp_Goodsbiz"%>
<%@page import="com.zking.biz.IGoodsbiz"%>
<%@page import="com.zking.entity.OrderItem"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String number=request.getParameter("gn");
int count=1;
if(number!=null){
	count=Integer.valueOf(number);
}
String uid=session.getAttribute("a")+"";
int uuid=Integer.valueOf(uid);
String id=request.getParameter("bid");
int bid=Integer.valueOf(id);
//创建订单对象
OrderItem d=new OrderItem();
//使用多态创建商品业务逻辑层和实现类
IGoodsbiz igb=new Imp_Goodsbiz();
IorderItembiz iot=new Imp_orderItembiz();
Goods gd=new Goods();
gd=igb.getById(bid);
int oid=DBHelper.getNextId("OrderItem", "oid");
d.setOid(oid);
d.setUuid(uuid);
d.setBid(bid);
d.setBname(gd.getBname());
d.setBprice(gd.getBprice());
d.setBinfo(gd.getBinfo());
d.setBface(gd.getBface());
d.setGnumber(1);
d.setGprice();
ArrayList slist=iot.getAll(uuid);
	boolean b=true;
	for(int i=0;i购物车2.0版本(连接数据库)_第3张图片

 


删除将订单ID传到sc.jsp进行删除

<%@page import="com.zking.biz.imp.Imp_orderItembiz"%>
<%@page import="com.zking.biz.IorderItembiz"%>
<%@page import="com.zking.entity.OrderItem"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<% 
String uid=session.getAttribute("a")+"";
int uuid=Integer.valueOf(uid);
IorderItembiz idb=new Imp_orderItembiz();
String id= request.getParameter("oid");
int oid=Integer.valueOf(id);
idb.deleteById(oid);
response.sendRedirect("gwc.jsp");

%>

购物车2.0版本就差不多是这些了,跟1.0版本相比,用数据库替代了seesion

你可能感兴趣的:(java)