Coldfusion 如何删除会话中存储的项目?

Coldfusion 如何删除会话中存储的项目?,coldfusion,cfml,Coldfusion,Cfml,我正在ColdFusion中使用一组结构。这是我试过的代码。有人能帮我更正代码吗 <cfif isDefined("remove")> //button in the cart page to remove a product <cflock scope="session" type="readonly" timeout="0200"> <cfparam name="Session.cart"> <cfloop que

我正在ColdFusion中使用一组结构。这是我试过的代码。有人能帮我更正代码吗

<cfif isDefined("remove")> //button in the cart page to remove a product
    <cflock scope="session" type="readonly" timeout="0200">
       <cfparam name="Session.cart">
       <cfloop query="#qProductSelected#"> //this is the query for getting productid from url
          <cfset sItem = structNew()> //this is my structure inside an array
          <cfset sItem.Image= Application.imageUrl&qProductSelected.ProductImage> //for getting image 
          <cfset sItem.ProductId =#ProductId#> //getting productid
          <cfset sItem.ProductImage = #Image#> //getting image
          <cfset sItem.ProductName = #ProductName#> //getting product name
          <cfset sItem.ProductDescription =#ProductDescription#> //getting productdescription
          <cfset sItem.quantity = form.qty> //storing quantity from form into the session
          <cfset structClear(sItem)> //finally i use structclear to clear the structure
        </cfloop>
   </cflock>
   <cflocation url="cart.cfm"> //redirecting to cart page itself
</cfif>
//购物车页面中用于删除产品的按钮
//这是从url获取productid的查询
//这是我在数组中的结构
//用于获取图像
//获取productid
//获取图像
//获取产品名称
//获取productdescription
//将表单中的数量存储到会话中
//最后,我使用structclear来清除结构
//重定向到购物车页面本身

如果您试图从会话中删除“购物车”密钥,可以执行以下操作:

<cfset StructDelete(session,'cart')>

但是,您处于只读锁中,因此需要将其更改为独占锁或不使用锁定。。。这取决于那里的情况


因为您正在使用购物车。我猜您将产品存储为结构数组,其中产品的详细信息存储在结构中。 如果您想从购物车中删除产品,代码如下所示

<cfset ArrayDeleteAt(session.arrCart,form.productsequenceincart) />

例如,如果有人点击了第三个产品的删除按钮,上面的代码就会这样做-

<cfset ArrayDeleteAt(session.arrCart,3) />

它将从购物车阵列中删除第三个产品


我们不需要对产品进行循环。

在较新版本的ColdFusion上,您可以执行
session.delete('cart')