当我将代码放入 View 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 Status 500 - An exception occurred processing JSP page /WEB-INF/view/cadastro.jsp at line 34
Projetro Controller
@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";
}
最佳答案
我认为您需要添加 <form:form>
在表单周围添加标记,如下所示:
<form:form>
<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>
</form:form>
在Spring官方文档中,它指出:
All the other tags in this library are nested tags of the form tag.
关于 Spring - JSP 表单 :input on jsp page error: jasperexception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23460245/