I am writing a spring boot application and have encountered the problem of sharing resources for different users. Simplified by example, it looks like this: there is one variable. You can assign a value to it through the form on the page. If the first user assigns the value hello java from one browser, then the second user will see the same value through another browser. I dont know how to make each user work with their own variable and their values do not overlap?
Controller:
@Controller
public class MessageController {
private String message;
@GetMapping(value = "/show_message")
public String showMessage(Model model){
model.addAttribute("message", message);
return "message";
}
@PostMapping(value = "set_message")
public String setMessage(@RequestParam(name = "newMessage") String newMessage){
message = newMessage;
return "redirect:/show_message";
}
}
html page:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
</head>
<body>
<p>Message value: <th:block th:utext="${message}"/></p>
<p>Enter a new message value</p>
<form method="POST" th:action="@{/set_message}">
<input type="text" name="newMessage"/>
<input type="submit" value="Send"/>
</form>
</body>
</html>