spring-security 使用html代码和spring boot的spring Boot 注册错误,我无法继续注册过程后,点击提交我得到了这个错误

gblwokeq  于 2022-11-11  发布在  Spring
关注(0)|答案(1)|浏览(152)

这是单击注册页面上的“提交”按钮后出现的错误消息

发生意外错误(类型=内部服务器错误,状态=500)。rawPassword不能为空值
第一个
这是登录页面的html代码。我没有做这个,我只是在互联网上找到它,并试图改变它,这样它就可以匹配我的用户实体,但我认为错误在这里,但我不能找到它通常的thobject,所以它匹配我的enity,我也修改了thfield,但正如我所说,我不知道要改变什么。我是一个html新手tho。

<!doctype html>
    <html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport"
            content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
            integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
      <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css"
            integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
      <title>Registration Form</title>
    </head>
    <body>
    <nav class="navbar navbar-expand-lg navbar-light bg-light" >
      <div class="container-fluid">
        <a class="navbar-brand" href="#">
          <img th:src="@{/images/logo.png}"  src="../static/images/logo.png" width="auto" height="40" class="d-inline-block align-top" alt=""/>
        </a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarSupportedContent">
          <ul class="navbar-nav mr-auto"></ul>
          <ul class="navbar-nav">
            <li class="nav-item active">
              <a class="nav-link" th:href="@{/}" href="#">home</a>
            </li>
            <li class="nav-item active">
              <a class="nav-link" th:href="@{/shop}" href="#">shop</a>
            </li>
            <li class="nav-item active">
              <a class="nav-link" href="#">Sign Up</a>
            </li>

          </ul>

        </div>
      </div>
    </nav>
    <div class="container">
      <div class="col-sm-6">
        <h3 style="margin-top: 10px">Sign Up Now</h3>
        <p>Please fill out this to register</p>
    <!--
        @thymesVar id="utilisateur" type="almanara.almanaraplateforme.Utilisateur.Utilisateur"
    -->
        <form th:action="@{/register}" th:object="${utilisateur}" method="post">
          <div class="form-group">
            <label for="firstName">First Name</label>
            <input type="text" name="firstName" id="firstName" required placeholder="Your Firstname" class="form-control form-control-lg">
          </div>
          <div class="form-group">
            <label for="lastName">Last Name</label>
            <input type="text" name="lastName" id="lastName" required placeholder="Your Lastname" class="form-control form-control-lg">
          </div>

          <div class="form-group">
            <label for="password">Password</label>
            <input type="password" class="form-control form-control-lg" required placeholder="Password" name="password"
                   id="password">
          </div>
          <div class="form-group">
            <label for="telephone">telephone</label>
            <input type="number" name="lastName" id="telephone" required placeholder="telephone" class="form-control form-control-lg">
          </div>
          <div class="form-group">
            <label for="email">Email address</label>
            <input type="email" class="form-control form-control-lg" required minlength="6" placeholder="Email" name="email" id="email"
                   aria-describedby="emailHelp">
            <small id="emailHelp" class="form-text text-muted">We'll never share your email with
              anyone else.</small>
          </div>
          <div class="form-group">
            <label for="adresse">adresse</label>
            <input type="text" name="adresse" id="adresse" required placeholder="adresse" class="form-control form-control-lg">
          </div>
          <div class="form-group">
            <label for="emploi">emploi</label>
            <input type="text" name="emploi" id="emploi" required placeholder="emploi" class="form-control form-control-lg">
          </div>
          <div class="form-group">
            <label for="region">region</label>
            <input type="text" name="region" id="region" required placeholder="region" class="form-control form-control-lg">
          </div>
          <div class="form-group">
            <label for="secteur">secteur</label>
            <input type="text" name="lastName" id="secteur" required placeholder="secteur" class="form-control form-control-lg">
          </div>
          <input type="submit" value="Register" class="btn btn-primary btn-block">
          <span style="margin-top: 10px">Already have an account <a class="linkControl" href="./login.html"
                                                                    th:href="@{/login}">Login here</a></span>
        </form>
      </div>
    </div>

    <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    </body>
    </html>
ogsagwnx

ogsagwnx1#

根据您的错误堆栈跟踪

java.lang.IllegalArgumentException: rawPassword cannot be null
    at org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder.encode(BCryptPasswordEncoder.java:107)

它只是意味着您传递给bCryptPasswordEncoder.encode(password)的密码变量为空。

Utilisateur.setPasswordUtl(bCryptPasswordEncoder.encode(password));

并且在您的表单从前端提交后它将为空的唯一原因是

*您尚未将html属性与模型属性正确Map。

并且将null传递给编码器并引发错误。

根据以下建议更正您的thymleaf html模板。

更改下面的html以正确MapModelAttribute中的详细信息。

<div class="form-group">
    <label for="password">Password</label>
    <input type="password" class="form-control form-control-lg" required placeholder="Password"
                       name="passwordUtl"
                       id="password">
</div>

您正在将html标记定义为name="password",而它应该按照您在实体类name="passwordUtl"中定义的属性。
您的实体类具有不同的命名变量,并且您在html中使用了不同的名称。
根据您的实体类属性名称,按照上面的建议更正所有其他html names

相关问题