我正在使用弹簧启动/Thymeleaf创建一个接受电子邮件地址的表单,重定向到显示已接受电子邮件的结果页面,并将其发送到第三方API(通过Oauth2进行身份验证)。我在表单部分遇到问题,我正在尝试使用Thymeleaf接受输入以将其显示在结果.html页面上。当我尝试在结果页面上显示它时收到错误,完整错误是:
[THYMELEAF][http-nio-8080-exec-4] Exception processing template "result.html": Exception evaluating SpringEL expression: "signup.email" (template: "result.html" - line 10, col 4)
我试图遵循这里提供的例子:https://spring.io/guides/gs/handling-form-submission/
我已尝试修改控制器,并添加解决方法中描述的注释,例如:@PostMapping@GetMapping@RequestMapping
<!--/*@thymesVar id="signup" type="com.mainconfig.controller1"*/-->
下面是包含窗体的代码:signup.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html>
<head>
<title>My Jmml</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body style="background-color: #2B2B2B">
<br /><br />
<h2 style="text-align:center">Contact Information</h2>
<!-- Input Form -->
<!--/*@thymesVar id="signup" type="com.mainconfig.controller1"*/-->
<form action="#" th:action="@{/signup}" th:object="${signup}" method="post">
<div align="center">
<label>Email Address</label><br /><br />
<!--/*@thymesVar id="email" type="String"*/-->
<input type="text" th:field="*{email}" placeholder="Email" required />
<br />
<br />
<input class="submitbutton" type='submit' value='Submit'/>
<br />
</div>
</form>
</body>
</html>
应显示电子邮件(结果.html)的结果页面:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Thank you for your submission!</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Thank you for your submission!</h1>
<p th:text="'Email: ' + ${signup.email}" />
<a href="/index">Submit another message</a>
</body>
</html>
预期输出应该是在注册表单中收集后显示在结果页面上的电子邮件变量。
如果您对如何更好地完成我正在尝试的工作有建议,我愿意接受建议!我是春天/百叶的新手,但有Java / Jsp的经验,谢谢你的任何帮助,请让我知道,如果你需要任何其他帮助!
手掌心
相关分类