1. 購物車技術實現過程中需要用到的jsp對象有哪些
JSP編程技術5-購物車的實現-session會話對象 - CSDN博客
2. 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;
}
}
----------------------------------------------------------------------
上面是一個簡單的例子,功能都能實現,對網頁效果要求更漂亮些的可做一些修改。
3. 在JSP中怎樣實現購物車計數
問題比較怪異~
既然都會做購物車了~那麼計數又又什麼難的?
無非都是統計數字專罷了~
如果是問的購物車中總共又屬多少類商品,那麼只要統計集合中又多少個商品對象就可以了,用count或者size方法(視你所用集合而定)
如果問的是每類商品有多少個,那麼只要再再商品對象中加一個數量的屬性就OK了,無論增加或減小商品數量也只要修改這個屬性的值就可以~
4. jsp中購物車實現的思路該如何解決
點擊復商品
寫庫 頁面展示制 2.商品 新增 插入數據 刪除 移除數據 修改 +直接修改 -判斷數量是否小於1是 刪除數據
生產訂單 購物車數據 移交訂單詳細表 生成訂單表 移除購物車數據表
以上為簡單邏輯 更具你的需求自行更改
5. 用jsp製作購物車中,怎麼實現購買數量改變,總價隨之改變
<input type="text" onpropertychange="changesum();" id="goodCount" value="0"/><input type="text" id="sumprice" value=""><script type="text/javaScript">function changesum(){ var count = document.getElementById("goodCount").value; document.getElementById("sumprice").value=10.1*count;
}
</script> }</script>
6. jsp+servlet做的購物網站怎麼綁定用戶和購物車(實現每個用戶有獨立的購物車)
當然是持久化到資料庫中了;
建一個購物車表,用戶ID作為外鍵約束,添加刪除內購物車的時候直接容操作資料庫就行了;
如果要實現用戶不登錄也有購物車的功能,就加一個cookie,把商品存在cookie里,瀏覽器不關閉就都在;
7. 用JSP做個網站實現購物車功能
建個購物車對象
把購買好的 商品 放到 一個 集合里
再把 集合 存到 session中
然後 增刪改查 都 操作 session中的 集合
就OK了 不是很難 你試著 寫下 這樣 提高才會快
8. jsp購物車計算數量的問題!
總計只能是每次改動要更新一次咯。沒次算完小計後,再吧所有小計加起來得總計。
9. 求ejb+jsp實現簡單購物車功能的代碼
修改下述的例子,增加web功能
(1)提供登錄頁面Login.jsp;
只需要登錄名與密碼(可在程序中硬編碼)
(2)圖書列表頁面
列出所有可出售的圖書供用戶選擇;
圖書只需給出圖書名(可在程序中硬編碼)
(3)提供購物車商品的管理頁面:
能夠向購物車中添加圖書(從圖書列表中選擇);
能夠刪除購物車中的圖書;
能夠察看購物車中的圖書信息
(4)用戶可主動退出系統
一個EJB例子如下(購物車)
import java.util.*;
import javax.ejb.Stateful;
import javax.ejb.*;
@Stateful(mappedName="cart")
public class CartBean implements Cart{
String customerName;
String customerId;
List<String> contents;
//ArrayList<String> contents;
public void initialize(String person) throws BookException {
if (person == null) {
throw new BookException("不允許沒有用戶!");
} else {
customerName = person;
}
customerId = "0";
contents = new ArrayList<String>();
}
public void initialize(String person, String id)
throws BookException {
if (person == null) {
throw new BookException("不允許沒有用戶!");
} else {
customerName = person;
}
IdVerifier idChecker = new IdVerifier();
if (idChecker.validate(id)) {
customerId = id;
} else {
throw new BookException("無效的ID: " + id);
}
contents = new ArrayList<String>();
}
public void addBook(String title) {
contents.add(title);
}
public void removeBook(String title) throws BookException {
boolean result = contents.remove(title);
if (result == false) {
throw new BookException(title + " 不在購物車中。");
}
}
public List<String> getContents() {
return contents;
}
@Remove()
public void remove() {
contents = null;
}
}