在spring mvc显示中,在jsp的下拉列表中显示默认值

时间:2017-02-03 02:37:03

标签: spring jsp model-view-controller

我在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);
}

1 个答案:

答案 0 :(得分:0)

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

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