一尘不染

Spring-JSP形式:在jsp页面上输入错误:jasperexception

spring-mvc

当我将代码放在cadastro.jsp的form:form标记内时:

<div class="form-group">
<label for="nome" class="col-sm-2 control-label"> name Project: </ label>
<div class="col-sm-10">
<input for="nome" class="form-control" />
<form:errors path="nome" />
</div>
</div>

其作品

但是当我放

<div class="form-group">
<label for="nome" class="col-sm-2 control-label"> Nome do Projeto: </ label>
<div class="col-sm-10">
<form:input  cssClass="form-control" path="nome" />
<form:errors path="nome" />
</div>
</div>

无法使用,因为表单:输入标签

错误:

HTTP状态500-在第34行处理JSP页面/WEB-INF/view/cadastro.jsp时发生异常

ProjetroController

@RequestMapping(value = "/novoProjeto", method = RequestMethod.POST)
public String adicionarProjeto(@Valid @ModelAttribute("projeto") Projeto projeto, BindingResult result) {
    if(result.hasErrors()) {
        return("cadastro");
    }
    projeto.setStatus("NOVO");
    this.pc.salvar(projeto);
    return "redirect:/listar";

}

阅读 260

收藏
2020-06-01

共1个答案

一尘不染

您必须导入spring形式taglib才能使用spring形式的elemnet:

将此添加到您的jsp顶部

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>

然后,您可以像这样使用:

<form:form id="myForm" method="post" action="/someAction" modelAttribute="formBean">            
     <form:label path="name"/>
     <form:input path="name"/>
<form:form>

并且您在控制器中添加了modelAttribute / command对象,例如:

@RequestMapping(value="/someUrl", method=RequestMethod.GET)
public String showForm(Model model){
   model.addAttribute("formBean", new FormBean());
   return "someViewName";
}

FormBean类看起来像:

public class FormBean {

  private String name;
  public FormBean(){} //default constructor

  //getter and setter for name
}
2020-06-01