我有一种情况,我被要求将文本字段更改为标签。我的负责人希望确保用户不会将文本字段与用户可以输入数据并想要标签的字段混淆。我做了必要的改变。但是当我尝试从表单中检索标签的值时,httpservletRequest 请求方法会为该字段返回一个空值。我通过使用具有标签中使用的相同变量并且有效的隐藏文本字段得到了解决方法。
我想知道:有没有办法将标签数据传递给request.getparameter,如果没有,为什么不呢?我怀疑由于它是一个标签,它不会传递任何东西,但想知道为什么不传递。
非常感谢。
You can't get the label values in the HttpServletRequest as only form variables are sent by the browser.
Browser can send the values for text fields, hidden fields, etc., but I don't think it going to send the label values(text) with the request.
But I don't understand why would you want to retrieve the label's value in the servlet?
One thing you can do is to have a hidden field for each label and keep a value in it.
But I don't think that's going to be useful.
而不是<label>您可以使用<input type="text" readonly="true" value="foo"/> Then 您可以为只读输入创建 CSS 样式。
.input[readonly] {
/* styles remove text boxes and format as a label */
}
我觉得有趣的隐藏字段的另一种替代方法是使用标签而不是标签,通过这样做,您可以检索 div 标签中的文本值。