简体   繁体   English

如何在jsp中访问spring mvc的表单对象?

[英]How do I access the form object of spring mvc in a jsp?

I have a form object with a form like : 我有一个表单对象,其形式如下:

<form:form commandName="search" id="xmsimplify-form" method="POST">
    <form:hidden path="typeOfSearch" />
    [...]
</form>

I would like to retrieved the value of the field typeOfSearch in the a scriplet in the header (before the actual tag form) 我想在标题中的scriplet中检索字段typeOfSearch的值(在实际标记表单之前)

<%
    String typeOfSearch = [????] 

    if ("somevalue".equals(typeOfSearch) ) {
        [...]
    }
%>

What would be the best thing to put instead of the [????]? 什么是最好的东西,而不是[????]?

If there a way to retrieve the form bean in the request attribute or that page attribue? 如果有办法在请求属性或该页面属性中检索表单bean?

Thanks 谢谢

The recommended method would be do it JSTL style 推荐的方法是做JSTL风格

<c:if test='${search.typeOfSearch == "somevalue"}'>
    [...]
</c:if>

But if you really want you can pull objects from the model map directly from the request. 但如果您真的想要,可以直接从请求中提取模型图中的对象。

final SomeForm form = (SomeForm) request.getAttribute("someForm");
if(form.getTypeOfSearch().equals("somevalue") {
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM