Take the 2-minute tour ×

How to pass a hidden value in a form in Spring MVC 3.0

I am not able to assign a value to a hidden field using <form:hidden path="test" />. How can I set the value of the test field and access it on the server side.


share|improve this question
Is test a member variable of your command/form object? –  Raghuram Mar 17 '11 at 11:46
yes ... it part of the modelAttribute <form:form method="post" action="/add" modelAttribute="Rules" > <form:hidden path="test" /> </form:form> –  Santhosh S Mar 17 '11 at 12:00
Can you post your controller code please? –  Scobal Mar 17 '11 at 12:55
@RequestMapping(value = "/add", method = RequestMethod.POST) public ModelAndView addRules( @ModelAttribute("Rules") Rules rules, BindingResult result ) throws Exception { ...... } –  Santhosh S Mar 18 '11 at 5:53
Have you checked the BindingResult object for any errors? If 'test' cannot be bound to the Rules model attribute you will see an error in there –  Scobal Mar 28 '11 at 19:46

3 Answers 3

<form:hidden path="test"  style="display:none"/>
share|improve this answer
I've upvoted this, and used it: but I'm wondering why on earth this works. It looks and feels like a hack! Why doesn't it just work without the style bit? –  mwarren Nov 27 at 16:05

It is oblibiuos that besides a hidden tag you also have a form like this:

<form:form action="/someAction" commandName="formBeanName" method="post">]
        there you set needed properties
    <form:hidden path="test" />

Notice that the "formBeanName" is attribute name of java class, that was stored in HttpServletRequest, so you can simple use it as a bean! Also do not forget to add setter and getter to your secret property.

<%--Set you secret property there--%>   
<jsp:setProperty name="formBeanName" property="test" value="sercret"/>

        there you set needed properties
    <form:hidden path="test" />

public class FormBean {

    //other fileds

    private String test;

    public String getTest(){
        return this.test;

    public String setTest(Strign test){
        return this.test = test;

P.S. I tested this with Spring 3.1

UPDATED: This example works unstable. I do know why, but sometimes it set property, somewhere no. If you have two spring forms in one jsp this approach can set property for first and not set for second or vice versa. May be because jsp:setProperty work after spring forms tag, may be not.

share|improve this answer

Often people wrongly pass some values as hidden to form, because they cannot otherwise set those fields in update to previous values. E.g If I don't pass some values while updating to the form, those fields become null. However this is wrong way to update values. There is


to do that. After you update, you can set the session to complete using (SessionStatus status) parameter and status.setComplete() after the update is done. If you want to get some values that is not in model you can always use request.getParameter("yourinputname"); You can use

input type="hidden"

to set some values if you want to use in some parts like javascript (if using


does not work).

And if you really want to access the hidden filed try using


before looking at binding errors.

share|improve this answer

Your Answer


