使用Spring标记库在JSP中显示值

使用Spring标记库在JSP中显示值,spring,model-view-controller,spring-mvc,Spring,Model View Controller,Spring Mvc,有没有办法用Spring标记库显示bean中已经填充的值?我知道我们可以使用${}符号来查看值。我正在尝试做如下事情: <form:form commandName="studentBean" method="POST"> <form:input path="fName"></form:label> </form:form> 如果我想更新这些值,这是可以的,但是它不会显示commandBean中已经存在的值。有人能发布解决方案吗?应该是这样的

有没有办法用Spring标记库显示bean中已经填充的值?我知道我们可以使用
${}
符号来查看值。我正在尝试做如下事情:

<form:form commandName="studentBean" method="POST">
<form:input path="fName"></form:label>
</form:form>


如果我想更新这些值,这是可以的,但是它不会显示
commandBean
中已经存在的值。有人能发布解决方案吗?

应该是这样的。(表单(xmlns:form=)http://www.springframework.org/tags/form“”)输入字段应预先填充您在呈现jsp页面结果的控制器的命令对象中输入的值

可能您没有填充模型

@RequestMapping(value = "/xxx", params = "form", method = RequestMethod.GET)
public ModelAndView updateForm() {
    ...
    StudentBean studentBean = new StudentBean();
    studentBean.setFName("Ralph");
    return new ModelAndView("updateForm", "studentBean", studendBean);
}

@RequestMapping(value = "/xxx", method = RequestMethod.POST)
public ModelAndView update(@Valid StudentBean studentBean,
                           final BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        return new ModelAndView("updateForm", "studentBean", studendBean);
    } else {
        ...
        return new ModelAndView(new RedirectView("/finished", true));
    }
}
因此,最终需要两个方法,一个用于填充表单/command/bean initial,另一个用于处理用户输入

顺便说一句:术语“Bean”对于用于填充表单并包含请求的对象来说非常少见。(在JSF中,它被称为(托管)Bean,但您使用的是JSP(这是命令库,与基于组件的JSF不可比)。它也不是Spring Bean,因为它不是Spring托管对象。--我个人使用术语“command”来表示这类对象。(根据Spring参考:“将参数绑定到的命令或表单对象:…”)