0

ユーザーが子犬情報を入力するための jsp が 1 つあります。

<FORM  action="/publish" method="post" commandName="puppy" >
    <table border=0 cellspacing=0 cellpadding="0">
       <% String[] textFields = {"category", "name", "gender", "age", "price"};
            for (int j= 0; j<textFields.length; j++){      %>
            <tr>  <td> <%=textFields[j]%>:                        </td>
                  <td> <input type=text name=<%=textFields[j]%>>  </td>
            </tr>
           <% } %>
    </table>
    <input type = "submit" value="submit">
</FORM>

カテゴリ、名前、性別、年齢、価格を含む子犬オブジェクトがあります。

コントローラーで、ユーザーが書いた子犬の情報を取得したい

@RequestMapping(value = "/publish")
public String publish (@ModelAttribute("puppy") Puppy newP, BindingResult result){
        System.out.println("Puppyname: " + newP.getName());
        return "redirect:publish.jsp";
}

これは機能しません。助けてくれてありがとう!

4

2 に答える 2

0

Spring MVC タグ lib を使用する必要があります。Puppyクラスの各プロパティの入力をフォームに入れます。次に例を示します。

<s:input  path="name" />

明らかに、クラスに, , ,プロパティが必要でありcategory、それらのパブリック アクセサーが必要です。namegenderagepricePuppy

于 2012-09-17T15:04:40.463 に答える
0

Spring 3.1+ RedirectAttributes (別名 FlashAttributes) はあなたの友達です。

例を含むランダムなブログ リンクhttp://vard-lokkur.blogspot.co.uk/2012/02/spring-mvc-flash-attributes.html

于 2012-09-17T15:02:26.890 に答える