*Registration From Application *
1.controller
package com.example.demo;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class Regn_controller {
@GetMapping("/")
public String display(Model model)
{
model.addAttribute("genders", List.of("Male","Female","Other"));
model.addAttribute("countries", List.of("Japan","U.S","Londan"));
model.addAttribute("hobbies", List.of("Football","Cricket","GYM"));
return "register";
}
@PostMapping("registered")
public String getDetails(@RequestParam String username,
@RequestParam String gene,
Model model)
{
model.addAttribute("name", username);
model.addAttribute("gend", gene);
return "success";
}
}
2.Register.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title> Registration Form</title>
</head>
<body>
<form action="registered" method="post">
<label> Name: </label>
<input type="text" name="username" placeholder="Enter Your Name" required>
<br><br>
<label> Gender: </label>
<input type="radio" name="gene"
th:each="gender:${genders}" th:value="${gender}" th:text="${gender}">
<br><br>
<label> Country: </label>
<select name="nation">
<option th:each="country:${countries}" th:value="${country}"
th:text="${country}">
</option>
</select>
<br><br>
<label> Hobby: </label>
<input type="checkbox" name="hob"
th:each="hobby:${hobbies}" th:value="${hobby}"
th:text="${hobby}">
<br><br>
<input type="submit" value="Enter Details">
</form>
</body>
</html>
3.Success.html
Registered Successfully
<p th:text="${name}">
</p>
<p th:text="${gend}">
</p>
OUTPUT
Top comments (1)
keep doing this bro