Woot4Moo
Woot4Moo

Reputation: 24336

Pass drop down list value from jsp to spring controller

Given the following code:

@Controller  
public class Foo  
{  
    public void foo(@RequestParam("dropDown") String value)  
    {
           ...
    }  
}  

and a jsp:

<div>   
    <form action="/foo">  
      <select id="dropDown">
            <option value="bar">bar</option>

     </select>
    </form>   
</div>

How can I pass back the value that gets selected in the dropDown id back to my Spring controller? As it stands I get invalid request parameters when I attempt ot execute this.

Upvotes: 0

Views: 10238

Answers (2)

Woot4Moo
Woot4Moo

Reputation: 24336

<div>   
    <form action="/foo">  
      <select name="dropDown">
            <option value="bar">bar</option>

     </select>
    </form>   
</div>

Upvotes: 3

RoryB
RoryB

Reputation: 1047

Have you got the @RequestMapping annotations set up in your controller, so that submitted form is returned to the correct method? In this case, you'd want:

@RequestMapping(method = RequestMethod.POST)

On your foo() method, I think.

See http://static.springsource.org/spring/docs/3.0.0.M3/reference/html/ch16s11.html for more information.

Upvotes: 0

Related Questions