在Spring MVC 3.0中如何在窗体中传递隐藏值
我不能使用<form:hidden path="test" />为隐藏字段赋值。如何设置test字段的值并在服务器端访问它。
谢谢
发布于 2014-09-22 16:45:01
<form:hidden path="test" style="display:none"/>发布于 2013-03-14 21:15:57
除了一个隐藏的标签之外,你还有一个像这样的表单,这是很奇怪的:
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<form:form action="/someAction" commandName="formBeanName" method="post">]
<%--
there you set needed properties
--%>
<form:hidden path="test" />
</form:form>请注意,"formBeanName“是存储在HttpServletRequest中的java类的属性名,因此您可以简单地将其用作bean!另外,不要忘记将setter和getter添加到您的secret属性中。
<%--Set you secret property there--%>
<jsp:setProperty name="formBeanName" property="test" value="sercret"/>
<form:form action="/someAction" commandName="formBeanName" method="post">]
<%--
there you set needed properties
--%>
<form:hidden path="test" />
</form:form>
public class FormBean {
//other fileds
private String test;
public String getTest(){
return this.test;
}
public String setTest(Strign test){
return this.test = test;
}
}附注:我用Spring 3.1测试了这一点
更新:此示例适用于不稳定的。我确实知道为什么,但有时它会设置属性,在某个地方没有。如果在一个jsp中有两个spring表单,这种方法可以为第一个设置属性,而不为第二个设置属性,反之亦然。可能是因为jsp:setProperty在spring forms标签之后工作,可能不是。
发布于 2011-06-02 09:41:09
人们经常错误地将一些值作为隐藏传递给表单,因为他们无法以其他方式将这些字段设置为以前的值。例如,如果我在更新到表单时没有传递一些值,这些字段就会变为空。然而,这是错误的更新值的方式。的确有
@SessionAttributes(“规则”)
要做到这一点。更新后,您可以使用(SessionStatus状态)参数和status.setComplete()将会话设置为在更新完成后完成。如果你想获取一些不在模型中的值,你可以使用request.getParameter("yourinputname");你可以使用
输入type=“隐藏”
如果您想在某些部分中使用,如javascript,则设置一些值(如果使用
${somevalueIdontwanttoshow}
不起作用)。
如果您真的想访问隐藏字段,请尝试使用
request.getParameter("yourfiedl")
在查看绑定错误之前。
https://stackoverflow.com/questions/5338469
复制相似问题