0

これはかなり簡単なはずですが、いくつかのことを試した後、行き詰まりました。私はjspに基本的なドロップダウンリストを表示しようとしているだけです。Spring のバージョンは 3 なので、すべてアノテーションで動作するようにしたいです。

ドロップダウン リストを含む JSP フォーム:

<form:form method="post" commandName="countryForm">
                    <table>
                        <tr>
                            <td>Country :</td>
                            <td><form:select path="country">
                                    <form:option value="Select" label="Select" />
                                </form:select>
                            </td>

                        <tr>
                            <td colspan="3"><input type="submit" /></td>
                        </tr>
                    </table>
                </form:form>

CountryForm.java は、getter と setter を持つ単一の String 属性「country」を持つプレーンなオブジェクトです。

GET リクエストを処理するコントローラーは次のとおりです。

@Controller
public class CountryFormController {

@RequestMapping(value = "MainView", method = RequestMethod.GET)
    public String showForm(Map model) {
        CountryForm cform = new CountryForm();
        model.put("countryForm", cform);
        return "MainView";
    }
}

ただし、JSP「MainView」にリダイレクトすると、典型的なエラーが発生します。

org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'countryForm' available as request attribute
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:424)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)

私は何を間違っていますか?

4

2 に答える 2

0

GitHubにサンプル コードがあります。試してみて、お知らせください。Landing.jspUserControllerを見てください。

<form:select path="users[${status.index}].type" >
  <form:option value="NONE" label="--- Select ---"/>
  <form:options itemValue="name" itemLabel="description" />
</form:select>

HTH

于 2013-04-22T01:20:55.017 に答える