當前位置:首頁 » 網購平台 » jsp不同用戶加入購物車代碼
擴展閱讀
寧波奧德賽優惠價格 2021-03-15 14:26:02
丹尼斯購物卡能掛失么 2021-03-15 14:25:58
淘寶購物指紋驗證失敗 2021-03-15 14:24:44

jsp不同用戶加入購物車代碼

發布時間: 2021-02-21 08:42:24

❶ 求有關jsp購物車的代碼

你的描述太簡單了,你告訴我你的架構,我給你寫一個。[email protected]你發給我看看吧,但我不確定一定能完成!

❷ 用jsp和資料庫做購物車,怎麼能通過點擊按鈕把購買數量和商品信息傳給購物車頁面,急!!下面是部分代碼

你把購買的數量和商品信息做成一個javabean,然後把這個javabean存在session裡面,你點擊按鈕就向伺服器端發出請求,然後伺服器端處理請求後用jsp顯示,這樣就可以了呀

❸ jsp購物車代碼

//shopping.html
<html>
<head><title>shopping stor</title></head>
<body>
<form action="carts.jsp" target="post">
<br>
please select the item that you want to buy
<br>
<select name="item">
<option>book:old man and the sea
<option>x-box game machine
<option>mp3 player
<option>cce
<option>book:jsp programming
<option>cd "the endless love"
<option>dvd "gone with the wind"
</select>
<br>
<input type="submit" name="submit" value="add">
<input type="submit" name="submit" value="remove">
</form>
</body>

</html>
------------------------------------------------------------------
//carts.jsp
<%@page contentType="text/html;charset=ISO8859_1" %>
<html>
<jsp:useBean id="cart" scope="session" class="test.DummyCart"/>
<jsp:setProperty name="cart" property="*"/>

<%
cart.processRequest();
%>
<br>
<ol>
you have chosen these items:
<%
String []items=cart.getItems();
for(int i=0;i<items.length;i++)
{
%>
<li><%=items[i] %></li>
<%
}
%>
</ol>
<hr>
<%@include file="shopping.htm" %>

</html>
---------------------------------------------------------------------//DummyCart.java
package test;
import javax.servlet.http.*;
import java.util.Vector;
import java.util.Enumeration;
public class DummyCart
{
Vector v = new Vector();
String submit=null;
String item= null;
private void addItem(String name)
{
v.addElement(name);
}

private void removeItem(String name)
{
v.removeElement(name);
}

public void setItem(String s)
{
item=s;
}

public void setSubmit(String s)
{
submit=s;
}

public String[] getItems()
{
String []s=new String[v.size()];
v.Into(s);
return s;
}

public void processRequest()
{
if(submit==null)
addItem(item);
if(submit.equals("add"))
addItem(item);
else if (submit.equals("remove"))
removeItem(item);
reset();
}

private void reset()
{
submit=null;
item=null;
}

}

----------------------------------------------------------------------
上面是一個簡單的例子,功能都能實現,對網頁效果要求更漂亮些的可做一些修改。

❹ jsp購物車:如何在不同頁面傳遞ArrayList對象

servlet 會不會啊?
基礎先打牢吧,先接觸點兒簡單的東西。
servlet傳遞對象的例子:
//mvc_login.htm
<form action="mvcdemo.mldn" method="POST">
輸入姓名:<input type="text" name="uname">
<input type="submit" value="提交">
</form>

//MVCCheck.java 封裝數據的類
package cn.mldn.lxh.bean ;

public class MVCCheck
{
private String name ;

public void setName(String name)
{
this.name = name ;
}
public String getName()
{
return this.name ;
}
// 驗證
public boolean isValidate()
{
if(this.name==null||"".equals(this.name))
{
return false ;
}
else
{
return true ;
}
}
};

//MVCServlet.java (含xml配置語句)
package cn.mldn.lxh.servlet ;

import java.io.* ;
import javax.servlet.* ;
import javax.servlet.http.* ;
import cn.mldn.lxh.bean.MVCCheck ;

public class MVCServlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException
{
this.doPost(req,resp) ;
}
public void doPost(HttpServletRequest req,HttpServletResponse resp) throws IOException,ServletException
{
String name = req.getParameter("uname") ;
MVCCheck dx = new MVCCheck() ;
// 將請求內容設置到mc對象之中
dx.setName(name) ;
String path = null ;
if(dx.isValidate())
{
// 保存「mc對象」在request范圍之中
req.setAttribute("dx",dx) ;
path = "mvc_success.jsp" ;
}
else
{
path = "mvc_failure.jsp" ;
}
// 進行跳轉
req.getRequestDispatcher(path).forward(req,resp) ;
}
};
/*
<servlet>
<servlet-name>mvc</servlet-name>
<servlet-class>cn.mldn.lxh.servlet.MVCServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>/mvcdemo.mldn</url-pattern>
</servlet-mapping>
*/

//mvc_success.jsp 接收對象

<%@page contentType="text/html;charset=gb2312"%>
<h1>輸入成功!!!</h1>
<h2>歡迎${dx.name}光臨!!!</h2>

❺ 求jsp購物車代碼

太長了
復制不下

❻ JSP購物車代碼詳解

SELECT 1
SCAN
SCATTER MEMVAR
SELECT 2
APPEND BLANK
GATHER MEMVAR
ENDSCAN

❼ jsp+servlet做的購物網站怎麼綁定用戶和購物車(實現每個用戶有獨立的購物車)

當然是持久化到資料庫中了;
建一個購物車表,用戶ID作為外鍵約束,添加刪除內購物車的時候直接容操作資料庫就行了;
如果要實現用戶不登錄也有購物車的功能,就加一個cookie,把商品存在cookie里,瀏覽器不關閉就都在;

❽ jsp購物車中,當多個用戶看中唯一商品時,都要加入購物車,用什麼方法解決

什麼嗎。商品唯一,為什麼要限制只能一個人買呢。
再說,如果用戶只是暫時放在購物車里了專,但真正屬付款的時候,他決定不買了,那豈不是耽誤了別人購買嗎。
所以你這種解決方案本身就不太好,應該在購買的再去解決沖突。 購買的方法設置一個同步就可以了。

❾ jsp購物車的代碼和資料庫

//購物車類ShoppingCart,僅供參考
packagebookshop;
importjava.util.*;
importjava.sql.*;
importjava.text.*;
publicclassShoppingCart{
HashMapitems=null;
publicShoppingCart(){
items=newHashMap();
}
publicsynchronizedvoidadd(StringbookID)throwsException{
if(items.containsKey(bookID))
{
ShoppingCartItemitem=(ShoppingCartItem)items.get(bookID);
item.quantity++;
}
else
{
Stringsql="SELECT*FROMtb_BookWHEREbookID='"+bookID
+"'";
DBHandledbhandle=newDBHandle();
ResultSetrs=dbhandle.executeQuery(sql);
ShoppingCartItemnewItem=newShoppingCartItem();
if(rs.next()){
newItem.bookID=bookID;
newItem.isbn=rs.getString("ISBN");
newItem.bookName=rs.getString("bookName");
newItem.bookImage=rs.getString("bookImage");
newItem.categoryID=rs.getString("categoryID");
newItem.author=rs.getString("author");
newItem.price=rs.getFloat("price");
newItem.description=rs.getString("description");
newItem.quantity=1;
dbhandle.closeResource();
items.put(bookID,newItem);
}
}
}

publicsynchronizedvoidsetItem(StringBookID,intnum){
if(items.containsKey(BookID)){
ShoppingCartItemitem=(ShoppingCartItem)items.get(BookID);
item.quantity=num;
}
}

publicsynchronizedvoidremove(StringBookID){
items.remove(BookID);
}

(){
Collectionc=items.values();
returnc.iterator();
}

protectedvoidfinalize()throwsThrowable{
items.clear();
}

(){
returnitems.size();
}

(){
doubleamount=0.0;
for(Iteratori=getItems();i.hasNext();){
ShoppingCartItemitem=(ShoppingCartItem)i.next();
amount+=item.quantity*item.price;
}
returnroundOff(amount);
}

privatedoubleroundOff(doublex){
longval=Math.round(x*100);//cents
returnval/100;
}

publicsynchronizedvoidclear(){
items.clear();
}

publicintpayOrder(StringuserName,StringtrueName,Stringpostcode,
Stringaddress,Stringtelephone,Stringmemo)throwsException{
Connectionconn=null;
intorderID=0;
DBHandledbhandle=newDBHandle();
try{
conn=dbhandle.getConnection();
conn.setAutoCommit(false);

Statementstmt=conn.createStatement();
doubletotal=getTotal();
SimpleDateFormatdataFormat=newSimpleDateFormat(
"yyyy-MM-ddHH:mm:ss");
StringorderDate=dataFormat.format(newjava.util.Date());
Stringsql="INSERTINTOtb_Orders(userName,trueName,address,postcode,tel,memo,totalPrice,isPay,isDeliver,orderDate)VALUES('"
+userName+"','"+trueName
+"','"
+address
+"','"
+postcode
+"','"
+telephone
+"','"
+memo
+"',"
+total+",'0','0','"+orderDate+"')";
System.out.println(sql);
stmt.executeUpdate(sql);
sql="SELECTMAX(orderID)ASmaxOrderIDFROMtb_Orders";//改動
System.out.println(sql);
ResultSetrs=stmt.executeQuery(sql);
rs.next();
orderID=rs.getInt(1);
Iteratori=getItems();
while(i.hasNext()){
ShoppingCartItemitem=(ShoppingCartItem)i.next();
intquantity=item.quantity;
Stringid=item.bookID;
doubleprice=item.price;
sql="INSERTINTOtb_OrderDetail(orderID,bookID,quantity,price)VALUES("
+orderID
+","
+id
+","
+quantity
+","
+price
+")";
stmt.executeUpdate(sql);
}
conn.commit();
conn.setAutoCommit(true);
}catch(Exceptionex){
conn.rollback();
System.out.println(ex.getMessage());
throwex;
}finally{
dbhandle.closeResource();
}
returnorderID;
}
}
//圖書信息類,ShoppingCartItem
packagebookshop;
publicclassShoppingCartItem{
publicStringbookID=null;
publicStringisbn=null;
publicStringbookName=null;
publicfloatprice=0.0F;
publicStringdescription=null;
publicStringbookImage=null;
publicStringauthor=null;
publicStringcategoryID=null;
publicintquantity;
}