5

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 ?

2 Answers 2

12

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Before our application starts, we need to ask our user to make a choice that is being held in a cookie; but it does sound like total overkill to put one value in a command class. That is why I was wondering if nothing else could be used.
Should parameters be passed in "{ /../} " ??
4

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.