2011-05-01 63 views
0

我可以使用錨標籤提交表單嗎?在這段代碼中,我使用了一個標準提交按鈕,但是如何使用錨定標記<a href=Cart?removeId=${cartItem.productId>Remove</a>使用錨鏈接進行表單提交

我試過了,但是在servlet中調用了doGet()方法。我想顯然調用doPost()方法。所以我可以使用更好的方法。

<c:forEach items="${lstCart}" var="cartItem" varStatus="count"> 
    <form action="Cart" method=Post> 
    <tr height="40px"> 

     <td>${count.count}</td> 
     <td>${cartItem.productName}</td> 
     <td>${cartItem.quantity}</td> 
     <td>${cartItem.unitPrice}</td> 
     <td>${cartItem.totalPrice}</td>  
     <td> 
     <input type="hidden" name="id" value="${cartItem.productId}" /> 
     <input type=submit value="x"></td> 

    </tr> 
    </form> 
</c:forEach> 

回答

2

您需要使用JavaScript來做一個錨點鏈接做一個帖子。不過,您可以使用CSS來設置提交按鈕的樣式,使其看起來更像鏈接。

0

是@JB表示您可以使用JScript發佈表單。下面我想到的一個例子是使用struts,在這裏你實際上是將產品ID作爲變量傳遞給JS方法(我改變了名稱以便與你的例子相匹配)。

<a href="#" onclick="removeProduct(${cartItem.productId})"> 
Remove 
</a> 

然後,您可以JS方法是

function removeProduct(productId) { 
document.forms["formname"].elements["productId"].value = 
productId; 
document.forms["formname"].submitTestPost.click(); 
} 

這還假定在頁面定義如下(所以JS可以將其設置),並提交財產(標籤SubmitTag)。我不確定你的情況,但也許你可以得出一些觀點。

<input type="hidden" name="productId"/>