Reputation: 2632
This is my code
<%
if(request.getParameter("cart") != null)
{
......
}
<%
<form method="post"><input class="auto-style2" height="44" name="cart"
src="divers/panier.jpg" type="image" width="71" />
So when I press the button name="cart" I can get request.getParameter("cart").
How to know its a post back when I click on the img
?
Upvotes: 0
Views: 1567
Reputation: 1108632
How to know its a post back when I click on the img ?
Check the request method.
if ("post".equalsIgnoreCase(request.getMethod())) {
// It's a POST request.
}
Or, better, let the form submit to a servlet and do the job in doPost()
method.
Unrelated to the concrete problem, you're in essence abusing the <input type="image">
here to have just a button with a background image. It will not sent a request parameter cart
, but instead send the mouse cursor position on the image as cart.x
and cart.y
. You need to check those parameters instead.
if (request.getParameter("cart.x") != null) {
// Image button is clicked.
}
See also HTML Input (type=image) not working on Firefox 4.
Upvotes: 1