Spring-JSP形式:在jsp页面上输入错误:jasperexception [英] Spring - JSP form:input on jsp page error: jasperexception

查看:62
本文介绍了Spring-JSP形式:在jsp页面上输入错误:jasperexception的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I put the code inside the form:form tag on view cadastro.jsp:

<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>

不起作用,因为形式:输入标签

not work because the form: input tag

错误:

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

HTTP Status 500 - An exception occurred processing JSP page /WEB-INF/view/cadastro.jsp at line 34

ProjetroController

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";

}

推荐答案

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

you have to import spring form taglib inorder to use elemnets of spring form like:

将此添加到您的jsp顶部

add this in top of your jsp

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

然后,您可以像这样使用

then, you can use like:

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

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

and you have add modelAttribute/command object in controller like:

@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
}

这篇关于Spring-JSP形式:在jsp页面上输入错误:jasperexception的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆