Controller
package springboot.demo.Controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import springboot.demo.Bean.Student;
import javax.servlet.http.HttpServletRequest;
@Controller
public class indexController {
@GetMapping("/login")
public String Login(HttpServletRequest request){
String username=request.getParameter("username");
String password=request.getParameter("password");
Student student = new Student(username,password);
request.getSession().setAttribute("username",username);
request.getSession().setAttribute("password",password);
return "Result";
}
@GetMapping("/")
public String index(){
return "Login";
}
}
Login.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Handling Form Submission</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="login" method="get">
<input type="text" name="username">
<input type="passwod" name="password">
<input type="submit">
</form>
</body>
</html>
Result.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Handling Form Submission</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
123
<p th:text="${session.username}"/>
<p th:text="${session.password}"/>
</body>
</html>