I just want to send the value of my dropdownlist with a requestparameter. In my case being
Kidscalcula_web/start.htm?klasid=myValueHere
I know a way of doing this but it sounds so irrational to use it for this. If I was bored I’d probably write some jQuery to do a post and send the parameter for instance.Now it really sounds like a very bad idea to manually make my requeststring, since Spring takes care of that. So how could I make a simple form that just sends my dropdownvalue to my controller?
It’s just that I can’t find something so trivial anywhere, and one of you can probably help me out quickly.I suppose the controller would be just as trivial as:
@RequestMapping(value = "post")
public String postIndex(@RequestParam("klasid") String klasid, HttpServletResponse response,
HttpServletRequest request) {
}
But I really can’t find any examples on how to make a JSP to send me that value. Is this possible with the <form>taglib ?
The
<form>taglib is generally used with form-backing command objects, rather than being bound to the controllers using individual@RequestParamarguments. This is why you won’t see any documentation examples of that combination being used together.For example, rather than having
@RequestParam("klasid"), you’d have a command class with a field calledklasid, and Spring would bind the whole lot together:This makes sense when you consider that forms typically have multiple parameters, and it’d get cumbersome to declare them all using
@RequestParam.Having said that, you can still do it – any form controls will generate request parameters that
@RequestParamcan bind to, but if you choose to deviate from Spring MVC’s form-backing command pattern, then it’s quite awkward.