Spring表格不适用于jsp

克里斯·哈德菲尔德(Chris Hadfield):

我是Spring框架的新手。我正在尝试在春季使用MySQL jdbc做简单的事情。对于数据映射,我使用了弹簧形式。每当我尝试使用弹簧形式时,它显示错误错误在这里

每当我删除弹簧形式并使用普通形式时,它看起来都不错,但在使用弹簧形式时却显示错误。错误显示java.lang.IllegalStateException:BeanResult'userData'的BindingResult或普通目标对象都不能用作请求属性

header.jsp

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

    </head>
    <body>
        <nav class="navbar navbar-inverse">
            <div class="container-fluid">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span> 
                    </button>
                    <a class="navbar-brand" href="#">SpringCRUDDemo</a>
                </div>
                <div class="collapse navbar-collapse" id="myNavbar">
                    <ul class="nav navbar-nav">
                        <li><a href="<c:url value='/'/>">Home</a></li>
                        <li><a href="<c:url value='/view/'/>">View</a></li>
                        <li><a href="#">Update</a></li> 
                        <li><a href="#">Delete</a></li> 
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
                        <li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
                    </ul>
                </div>
            </div>
        </nav>

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>

servlet类

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

谢谢 !希望得到一个好的回应

WoKak:
<form:form modelAttribute="userData">

   //rest of your form

</form:form>

在index.jsp中而不是当前版本中尝试此操作。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章