skip to Main Content

I am new to SpringBoot thymeleaf , I simple just make a registration
page ,but when I fill the registration details and hit the register
button in my registration page it throw below error
enter image description here

SignUpPage.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <link rel="stylesheet" th:href="@{/../css/SignUp.css}">
    <title>SIGN UP</title>
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    <script crossorigin="anonymous" src="https://kit.fontawesome.com/16e8cf656f.js"></script>
    <script type="text/javascript" th:src="@{/js/SignUp.js}"></script>
</head>
<body>

<div class="container">
    <div class="row py-5 mt-4 align-items-center">
        <!-- For Demo Purpose -->
        <div class="col-md-5 pr-lg-5 mb-5 mb-md-0">
            <img src="https://bootstrapious.com/i/snippets/sn-registeration/illustration.svg" alt="" class="img-fluid mb-3 d-none d-md-block">
            <h1>Create an Account</h1>
            <p class="font-italic text-muted mb-0">Create an account to enjoy some services freely.</p>
            </p>
        </div>

        <!-- Registeration Form -->
        <div class="col-md-7 col-lg-6 ml-auto">
            <form action="#" th:action="@{/saveUser}" th:object="${player}">
                <div class="row">

                    <!-- First Name -->
                    <div class="input-group col-lg-6 mb-4">
                        <div class="input-group-prepend">
                            <span class="input-group-text bg-white px-4 border-md border-right-0">
                                <i class="fa fa-user text-muted"></i>
                            </span>
                        </div>
                        <label for="firstName"></label><input id="firstName" type="text" th:field="*{firstName}" name="firstname" placeholder="First Name" class="form-control bg-white border-left-0 border-md">
                    </div>

                    <!-- Last Name -->
                    <div class="input-group col-lg-6 mb-4">
                        <div class="input-group-prepend">
                            <span class="input-group-text bg-white px-4 border-md border-right-0">
                                <i class="fa fa-user text-muted"></i>
                            </span>
                        </div>
                        <label for="lastName"></label><input id="lastName" type="text" name="lastname" th:field="*{lastName}" placeholder="Last Name" class="form-control bg-white border-left-0 border-md">
                    </div>

                    <!-- Phone Number -->
                    <div class="input-group col-lg-12 mb-4">
                        <div class="input-group-prepend">
                            <span class="input-group-text bg-white px-4 border-md border-right-0">
                                <i class="fa fa-phone-square text-muted"></i>
                            </span>
                        </div>
                        <label for="countryCode"></label><select id="countryCode" name="countryCode" style="max-width: 80px" class="custom-select form-control bg-white border-left-0 border-md h-100 font-weight-bold text-muted">
                            <option value="">+91</option>
                            <option value="">+972</option>
                            <option value="">+353</option>
                            <option value="">+39</option>
                            <option value="">+254</option>
                            <option value="">+852</option>
                            <option value="">+49</option>
                        </select>
                        <label for="phoneNumber"></label><input id="phoneNumber" type="tel" name="phone" th:field="*{phoneNumber}" placeholder="Phone Number" class="form-control bg-white border-md border-left-0 pl-3">
                    </div>.

                    <!-- Email Address -->
                    <div class="input-group col-lg-12 mb-4">
                        <div class="input-group-prepend">
                            <span class="input-group-text bg-white px-4 border-md border-right-0">
                                <i class="fa fa-envelope text-muted"></i>
                            </span>
                        </div>
                        <label for="email"></label><input id="email" type="email" name="email" th:field="*{email}" placeholder="Email Address" class="form-control bg-white border-left-0 border-md">
                    </div>

                    <!-- Password -->
                    <div class="input-group col-lg-6 mb-4">
                        <div class="input-group-prepend">
                            <span class="input-group-text bg-white px-4 border-md border-right-0">
                                <i class="fa fa-lock text-muted"></i>
                            </span>
                        </div>
                        <label for="password"></label><input id="password" type="password" name="password" th:field="*{password}" placeholder="Password" class="form-control bg-white border-left-0 border-md">
                    </div>
                    <!-- Submit Button -->
                    <div class="d-flex justify-content-center mx-4 mb-3 mb-lg-4">
                        <input class="btn btn-primary btn-lg" type="submit" value="Create Account" />
                    </div>

                    <!-- Divider Text -->
                    <div class="form-group col-lg-12 mx-auto d-flex align-items-center my-4">
                        <div class="border-bottom w-100 ml-5"></div>
                        <span class="px-2 small text-muted font-weight-bold text-muted">OR</span>
                        <div class="border-bottom w-100 mr-5"></div>
                    </div>

                    <!-- Social Login -->
                    <div class="form-group col-lg-12 mx-auto">
                        <a href="#" class="btn btn-primary btn-block py-2 btn-facebook">
                            <i class="fa fa-facebook-f mr-2"></i>
                            <span class="font-weight-bold">Continue with Facebook</span>
                        </a>
                        <a href="#" class="btn btn-primary btn-block py-2 btn-twitter">
                            <i class="fa fa-twitter mr-2"></i>
                            <span class="font-weight-bold">Continue with Twitter</span>
                        </a>
                    </div>

                    <!-- Already Registered -->
                    <div class="text-center w-100">
                        <p class="text-muted font-weight-bold">Already Registered? <a th:href="@{/login}" href="#" class="text-primary ml-2">Login</a></p>
                    </div>

                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>

Controller class

package com.nilmani.herokudemoapplication.controller

import com.nilmani.herokudemoapplication.entity.Player
import com.nilmani.herokudemoapplication.repository.PlayerRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.*


@Controller
class PlayerController {
    @Autowired
    private lateinit var playerRepository: PlayerRepository

    @GetMapping("/getSignUp")
    fun getRegistrationPage(model: Model,player: Player):String{
       model.addAttribute("player",Player())
        return "SIgnUpPage"
    }
    /**end point to register the user*/
    @PostMapping("/saveUser")
    fun registerUser(@ModelAttribute("player")player: Player,model: Model):String{
        model.addAttribute("player",Player())
        playerRepository.save(player)
        return "successPage"
    }
}

what is the reason for getting this type of issue
I know error 405 means it not supporting the function,But I define
everything properly ,why my code is not working I do not understand. I
am not able to find my mistakes.

2

Answers


  1. The "/saveUser" endpoint has method POST. The same needs to be reflected in the form element in SignUpPage.html.

    <form action="#" th:action="@{/saveUser}" th:object="${player}" th:method="POST">
    

    For more help refer to https://spring.io/guides/gs/handling-form-submission/

    Login or Signup to reply.
  2. Use th:method="POST" while submitting the form to the controller

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search