开发者

spring mvc: cleanest way for more than one submit button?

I have a a form and I'd like a next and back开发者_高级运维 button inside it. What is the cleanest way to do this in spring mvc? Just give the input type submit a name and value and check for that in my controller?


If you use Spring 3, you can distinguish between controller methods using params attribute:

<input type = "submit" name = "next" value = "Next" />
<input type = "submit" name = "back" value = "Back" />

.

@RequestMapping(..., params = "next")
public ModelAndView next(...) { ... }

@RequestMapping(..., params = "back")
public ModelAndView back(...) { ... }


You could do that, yes. Alternatively, don't use true submit buttons. Instead, use vanilla HTML buttons, with attached javascript handlers which later the form's target, and then programmatically submit the form.

Which one is "cleaner" depends on your point of view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜