Pass a request parameter in Spring MVC 3

后端 未结 2 1675
灰色年华
灰色年华 2021-01-18 15:20

I just want to send the value of my dropdownlist with a requestparameter. In my case being

Kidscalcula_web/start.htm?klasid=myValueHere

I

相关标签:
2条回答
  • 2021-01-18 15:39

    You don't even need a taglib to send this request. You can create a simpliest HTML form with method = "GET" (what is the default value of method):

    <form action = "...">
        <select name = "klasid">
            <option value = "value1">Option 1</option>
            <option value = "value2">Option 2</option>
            <option value = "value3">Option 3</option>
        </select>
        <input type = "submit" />
    </form>
    
    0 讨论(0)
  • 2021-01-18 15:47

    The <form> taglib is generally used with form-backing command objects, rather than being bound to the controllers using individual @RequestParam arguments. 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 called klasid, and Spring would bind the whole lot together:

    @RequestMapping(value = "post")
    public String postIndex(@ModelAttribute MyCommandClass command) { /../ }
    

    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 @RequestParam can bind to, but if you choose to deviate from Spring MVC's form-backing command pattern, then it's quite awkward.

    0 讨论(0)
提交回复
热议问题