2011-05-01 34 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"/>