Java Spring表单在jsp上不起作用
我不熟悉spring框架。我试图在spring中使用MySQL jdbc制作简单的crud。对于数据映射,我使用了spring表单。每当我尝试使用spring form时,它都会显示一个错误 每当我删除spring表单并使用normalform时,它看起来还可以,但在使用spring表单时会显示一个错误。错误为java.lang.IllegalStateException:bean名称“userData”的BindingResult和普通目标对象都不能作为请求属性使用 header.jsp 谢谢大家!!希望得到好的回应Java Spring表单在jsp上不起作用,java,spring,jsp,spring-mvc,spring-form,Java,Spring,Jsp,Spring Mvc,Spring Form,我不熟悉spring框架。我试图在spring中使用MySQL jdbc制作简单的crud。对于数据映射,我使用了spring表单。每当我尝试使用spring form时,它都会显示一个错误 每当我删除spring表单并使用normalform时,它看起来还可以,但在使用spring表单时会显示一个错误。错误为java.lang.IllegalStateException:bean名称“userData”的BindingResult和普通目标对象都不能作为请求属性使用 header.jsp 谢
<form:form modelAttribute="userData">
//rest of your form
</form:form>
请在index.jsp而不是当前版本中尝试此操作。请尝试添加
<%@include file="./shared/header.jsp" %>
<div class="container">
<form:form commandName="userData" action="#" method="post" enctype="multipart/form-data">
<label for="firstname" class="label">Enter your first name</label>
<form:input path="firstName"/>
</form:form>
</div>
@Controller
public class DefaultController {
@Autowired
CustomerDaoImp customerDaoImp;
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index() {
return "index";
}
@RequestMapping(value = "/insert", method = RequestMethod.POST)
public String save(@ModelAttribute("userData") Customer customer) {
try {
customerDaoImp.insert(customer);
} catch (ClassNotFoundException | SQLException ex) {
System.out.println(ex.getMessage());
}
return "redirect:/index";
}
@RequestMapping(value = "/view", method = RequestMethod.GET)
public String viewCustomer() {
return "view-customer";
}
}
<form:form modelAttribute="userData">
//rest of your form
</form:form>