spring mvc form:select 选项未显示在屏幕中但存在于 HTML 源代码中

spring mvc form:select option not displaying in screen but is there in HTML source

我正在使用 spring MVC 模型属性方法。打开屏幕时,我必须读取 JSON 字符串并创建地图。在下拉列表中显示地图。我可以在 HTML 源代码中看到值,但在屏幕上看不到下拉列表。

@RequestMapping("/xxx")
public ModelAndView saws(Map<String, Object> model1) throws IOException {
    ModelAndView model = new ModelAndView("xxx");
    model.addObject("message", this.welcome);
    Map<String, String> offers = engine.getOffers();
    model.addObject("offers", offers);//map of offers
    model.addObject("inputs", new inputs());
    return model;

}

JSP

<form:form action="getoffers" method="get" modelAttribute="inputs">
<body>
<table align="center">
        <tr class="blank_row">
            <td colspan="2"></td>
        </tr>
        <tr class="blank_row">
            <td colspan="2"></td>
        </tr>
        <tr align="center">
            <th span
                style="color: red; font-weight: bold; word-wrap: break-word;"
                align="center">Select the service to view current offers</th>
        </tr>
        <tr>
            <td><form:select path="offers">
                    <form:options items="${offers}" />
                </form:select></td>
        </tr>
    </table>

而且在屏幕上我没有看到下降 down.when 我检查了源代码我看到了这个。请看图片

假设您已经有了 sping-mvc 依赖项。

html 源文件不应有 <form:...> 前缀。它没有正确呈现。

将此放入您的 jsp 文件中:
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

我强烈建议您使用 Thymeleaf 模板引擎而不是 JSP。原因太长,无法放入此回答区。