[英]Using thymeleaf in my servlet, html template file not found
I am trying to use thymeleaf to read an html template, remplace a variable in it and then send it as an email. 我正在尝试使用百里香读取html模板,在其中重新放置变量,然后将其作为电子邮件发送。 However I am stuck at the part of reading the html template file.
但是,我被困在阅读html模板文件的部分。
This is the error i get: 这是我得到的错误:
The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>org.thymeleaf.exceptions.TemplateInputException: Error resolving template "invitationemail", template might not exist or might not be accessible by any of the configured Template Resolvers
org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:247)
org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1192)
org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1148)
org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1095)
org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1008)
org.thymeleaf.TemplateEngine.process(TemplateEngine.java:982)
yesterscape.ses.SESManagement.sendInvitationEmail(SESManagement.java:69)
yesterscape.users.InviteUserServlet.doPost(InviteUserServlet.java:68)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
So I am assumig it is because I am not properly setting my invitationemail.html file. 之所以这样,是因为我没有正确设置我的Invitationemail.html文件。
This is the code to read the email and change the value: 这是读取电子邮件并更改值的代码:
ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
resolver.setTemplateMode("HTML5");
resolver.setSuffix(".html");
TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(resolver);
final Context context = new Context(Locale.US);
context.setVariable("name", nameFrom);
final String htmlVer = templateEngine.process("invitationemail", context);
As you can see, I am setting the suffix as .html and in the name of the file to process i am just typing "invitationemail". 如您所见,我将后缀设置为.html,并在要处理的文件名中输入“ invitationemail”。 But still it cannot be found.
但是仍然找不到。
In what folder of my servlet architecture should I include the invitationemail.html file? 我应该在servlet体系结构的哪个文件夹中包含Invitationemail.html文件? I thought it should be in the WEB-INF folder, and this is where it currently is but I still have no luck.
我以为它应该在WEB-INF文件夹中,这是当前位置,但是我仍然没有运气。
Thanks in advice for any assistance you can provide. 感谢您提供任何帮助的建议。
Instead of ClassLoaderTemplateResolver
use another ITemplateResolver
implementation as follows 代替
ClassLoaderTemplateResolver
使用另一个ITemplateResolver
实现,如下所示
ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
resolver.setPrefix("/WEB-INF/template/");
resolver.setSuffix(".html");
resolver.setTemplateMode("HTML5");
// ... etc
And put you email template into /WEB-INF/template
folder.. 并将您的电子邮件模板放入
/WEB-INF/template
文件夹。
Problem fixed. 问题已解决。 When using the ClassLoaderTemplateResolver (which is the resolver needed for email content) the html files should be placed in the following directory:
使用ClassLoaderTemplateResolver(电子邮件内容所需的解析器)时,html文件应放在以下目录中:
WEB-INF/classes
WEB-INF / classes目录
Answer based on this post: http://forum.thymeleaf.org/springmail-sample-td3945553.html 根据这篇文章的答案: http : //forum.thymeleaf.org/springmail-sample-td3945553.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.