2016-09-05 5 views
0

リクエスト属性として使用可能なコマンド」」「BindingResultも要求属性として利用できるBean名 『コマンド』のプレーンなターゲットオブジェクトのいずれも」「春のフォームにBean名のためのタグライブラリ</p> <p>「BindingResultどちらもプレーンなターゲットオブジェクトを使用してフォームを作成しながら、私は例外を取得しています

JSPページがindex.jspを

<%@ include file="views/static_include.jsp" %> 
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Login to AVA Corp</title> 
</head> 
<body> 
<form:form method="POST" commandName="user" action="login.jsp"> 
<table> 
    <tbody><tr> 
     <td><form:label path="firstName">Name:</form:label></td> 
     <td><form:input path="firstName"></form:input></td> 
    </tr> 
    <tr> 
     <td><form:label path="age">Age:</form:label></td> 
     <td><form:input path="age"></form:input></td> 
    </tr> 
    <tr> 
     <td colspan="2"> 
      <input type="submit" value="Submit"> 
     </td> 
     <td></td> 
     <td></td> 
    </tr> 
</tbody></table>  
</form:form> 
</body> 
</html> 

Beanクラスである:

import java.io.Serializable; 

public class Person implements Serializable { 

    private static final long serialVersionUID = 1949001721422434327L; 

    private String firstName; 
    private Integer age; 

    public String getFirstName() { 
     return firstName; 
    } 

    public void setFirstName(String firstName) { 
     this.firstName = firstName; 
    } 

    public Integer getAge() { 
     return age; 
    } 

    public void setAge(Integer age) { 
     this.age = age; 
    } 

} 

コントローラクラスは、私は問題は=「GET」メソッドタイプとコントローラのメソッドであることがわかった

@Controller 
public class LoginController { 

    @RequestMapping(value = "/login", method = RequestMethod.GET) 
    public ModelAndView initForm(Model model) { 
     return new ModelAndView("index", "user", new Employee()); 
    } 

    @RequestMapping(value = "/login", method = RequestMethod.GET) 
    public String login(@ModelAttribute("user") Employee employee, BindingResult result, SessionStatus status){ 
     ModelAndView modelAndView = new ModelAndView(); 
     modelAndView.addObject("user", employee); 
     return "UserFormSuccess"; 
    } 
} 

答えて

0

です。リクエストメソッドの値は、フォームが存在するページのURLマッピングなどである必要があります。 index.jspの場合、コントローラクラスは

@Controller 
public class LoginController { 

    @RequestMapping(value = "/login", method = RequestMethod.GET) 
    public ModelAndView initForm(Model model) { 
     return new ModelAndView("index", "user", new Employee()); 
    } 

    @RequestMapping(value = "/login", method = RequestMethod.GET) 
    public String login(@ModelAttribute("user") Employee employee, BindingResult result, SessionStatus status){ 
     ModelAndView modelAndView = new ModelAndView(); 
     modelAndView.addObject("user", employee); 
     return "UserFormSuccess"; 
    } 
} 
です。
関連する問題

 関連する問題