以下是我正在尝试的代码
Home.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Welcome - ${result}</h1>
</body>
</html>
MainController.java
@Controller
@RequestMapping("/")
@Repository
@Transactional
public class MainController {
@Autowired
private UserLoginService uls;
@GetMapping
public String landingIndex(Model model) {
model.addAttribute("userLogin", new UserLogin());
return new String("index");
}
@RequestMapping(method=RequestMethod.POST)
public String insertingValue(@ModelAttribute @Valid UserLogin userLogin, BindingResult result,Model model) {
if(result.hasErrors()) {
return "index";
}else {
uls.saveUser(userLogin);
}
return new String("redirect:/home");
}
@GetMapping("/home")
public String landingToHome(Model model) {
model.addAttribute("result", "0");
return "Home";
}
}
输出: 每当我重定向到Home.jsp页面时,我都会得到以下
Welcome - ${result}