Spring のフォーム タグ ライブラリを使用しないのはなぜですか? http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/view.html#view-jsp-formtaglib
taglib (コントローラーと組み合わせて) は、ModelAttribute を自動的にマップします。フォームの GET リクエストを実行するとき、PostRequest の新しい (おそらく空の) オブジェクトを作成し、それをモデルに貼り付けます。POST 後、フォーム スプリングは ModelAttribute にフォーム値を提供します。
回路図の例:
コントローラ:
@RequestMapping(value="/path", method = RequestMethod.GET)
public String initForm(ModelMap model) {
PostRequest pr = new PostRequest();
model.addAttribute("command", pr);
return "[viewname]";
}
@RequestMapping(value="/path", method = RequestMethod.POST)
public ModelAndView postForm(
@ModelAttribute("command") PostRequest postRequest) {
// postRequest should now contain the form values
logger.debug("username: " + postRequest.getUsername());
return "[viewname]";
}
jsp:
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<form:form method="post" enctype="utf8">
Username: <form:input path="username" />
<br/>
<%-- ... --%>
<input type="submit" value="Submit"/>
</form:form>