[英]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: 和一个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? 如何将
dropDown
id中选择的值传回Spring控制器? As it stands I get invalid request parameters when I attempt ot execute this. 当我尝试执行此操作时,我得到无效的请求参数。
<div>
<form action="/foo">
<select name="dropDown">
<option value="bar">bar</option>
</select>
</form>
</div>
Have you got the @RequestMapping annotations set up in your controller, so that submitted form is returned to the correct method? 您是否在控制器中设置了@RequestMapping注释,以便将提交的表单返回到正确的方法? In this case, you'd want:
在这种情况下,您需要:
@RequestMapping(method = RequestMethod.POST)
On your foo()
method, I think. 我想你的
foo()
方法。
See http://static.springsource.org/spring/docs/3.0.0.M3/reference/html/ch16s11.html for more information. 有关详细信息,请参阅http://static.springsource.org/spring/docs/3.0.0.M3/reference/html/ch16s11.html 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.