如何获得HTML<输入类型=“图像">的值.在Servlet中 [英] How to obtain value of HTML <input type="image"> in the Servlet
问题描述
我的jsp中有此代码
<div class="controls">
<input type="image" class="sprite submit-button button" name="SubmitChangeCreds" value="ChangeUIDSubmit" src="../images/layout/transparent.png" />
</div>
在我的servlet中,我试图获取像这样的图像的值
In my servlet I am trying to get the value of this image like this
request.getParameter("SubmitChangeCreds")
但这是空的.
我们将不胜感激.
推荐答案
根据HTML规范,input type="image"
将用作图像映射.当最终用户单击图像映射时,Web浏览器会将鼠标指针的x和y位置发送到服务器.提交的值可用作originalname.x
和originalname.y
.
As per the HTML specification, the input type="image"
is to be used as an image map. The webbrowser will send the x and y position of the mouse pointer to the server when the enduser clicks on the image map. The submitted value is available as originalname.x
and originalname.y
.
所以在您的情况下:
String x = request.getParameter("SubmitChangeCreds.x");
String y = request.getParameter("SubmitChangeCreds.y");
但是,毕竟您似乎在滥用input type="image"
,因为您似乎对鼠标的位置不感兴趣.我建议只使用input type="submit"
,其中将图像指定为CSS背景图像.
However, you seem after all to be abusing the input type="image"
since you don't seem to be interested in the mouse position. I'd suggest to just use input type="submit"
wherein the image is specified as a CSS background image.
例如
<input type="submit" class="sprite submit-button button" name="SubmitChangeCreds" value="ChangeUIDSubmit" />
带有例如
.submit-button {
background-image: url('../images/layout/transparent.png');
}
这是按钮中背景图片的更正确用法.
That's a more correct usage of background images in buttons.
这篇关于如何获得HTML<输入类型=“图像">的值.在Servlet中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!