⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cart.jsp~3~

📁 jsp的图书购物系统
💻 JSP~3~
字号:
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page language="java" import="java.sql.*" %>
<%
if(session.getAttribute("username")==null)
{
	response.sendRedirect("login.html");
}
%>
<jsp:useBean id="cart" scope="page" class="book.bk" />
<%
String book_id=request.getParameter("book_id");
//是否已经选择该货物
    String sql="select id from 订单 where book_id="+book_id+" and user_name='"+session.getAttribute("username")+"'";
	ResultSet rs=cart.executeQuery(sql);
	int rowscount=0;
	try
	{
		while(rs.next())
		{
			rowscount++;
		}
	}
	catch(Exception e)
	{

	}
//把货物放入购物车
if(rowscount==0)
{
		String sqlBook1="select * from 书籍信息 where id="+book_id;
		ResultSet rsBook1=cart.executeQuery(sqlBook1);
		while(rsBook1.next())
		{
			String sqlCart="insert into  订单(user_name,book_id,book_number,goods_price)  Values('"+session.getAttribute("username")+"','"+book_id+"','1','"+rsBook1.getDouble("price")+"')";
			cart.executeQuery(sqlCart);
		}
}
else
{
		String sqlBook2="select * from 书籍信息 where id="+book_id;
		ResultSet rsBook2=cart.executeQuery(sqlBook2);
		while(rsBook2.next())
		{
			String sqlAdd="update 订单 set book_number=book_number+1,goods_price="+rsBook2.getDouble("price")+" where book_id="+book_id+" and user_name='"+session.getAttribute("username")+"'";
			cart.executeQuery(sqlAdd);
		}
}
response.sendRedirect("shopcart.jsp");
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -