【问题标题】:In spring mvc display with default values in dropdown in th jsp在 Spring mvc 中,在 jsp 的下拉列表中显示默认值
【发布时间】:2017-02-03 02:37:03
【问题描述】:

我在 JSP 上填充了目录,每一行都有一个 <button>,当我们单击该按钮时,表单值进入控制器,然后我使用 model.addAttribute() 将所有值设置为 jsp 在那个jsp中,一些字段现在是下拉列表我想将表单值显示为下一个Jsp的默认值,有人可以帮助我如何进一步进行吗?

我写的示例代码

在jsp中

<form:select path="country">
  <form:options items="${countryList}" itemLabel="country"/>
  </form:select>

在控制器方法中

@RequestMapping("/")
public String getClist(@ModelAttribute("form") FormBean fb){
  sysout(fb.getCountry());

  List<Country> c =userdao.getCountryList();

  model.addAttribute("countryList",c);
}

【问题讨论】:

  • 我没听明白,我的理解是您想向select 显示一个默认选项,例如“请选择选项”。如果我错了,请澄清。

标签: spring jsp model-view-controller


【解决方案1】:

这应该为您提供路径上已经存在的值,以及供进一步更改或选择的列表。

<form:select path="country">
  <form:option value="${country}" label="${country}" />
  <form:options items="${countryList}" itemLabel="country"/>
  </form:select>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-24
    • 1970-01-01
    • 2020-06-20
    • 1970-01-01
    相关资源
    最近更新 更多