admin管理员组文章数量:1026620
A ton of questions have been asked about connecting Thymeleaf + CSS and Spring Boot. I could not find any that addressed this problem with Ktor.
I have this template:
<!DOCTYPE html>
<html xmlns:th="; lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" th:href="@{/assets/css/style.css}">
</head>
<body>
...
</body>
</html>
This is what the file structure looks like:
src/main/resources/assets/css/style.css
src/main/resources/templates/thymeleaf/books.html
The templating plugin is set up in the following way:
fun Application.configureTemplating() {
install(Thymeleaf) {
setTemplateResolver(ClassLoaderTemplateResolver().apply {
prefix = "templates/thymeleaf/"
suffix = ".html"
characterEncoding = "utf-8"
})
}
}
This setup works fine without linking CSS, but when trying to link CSS, this error occurs:
.thymeleaf.exceptions.TemplateProcessingException: Link base "/assets/css/style.css" cannot be context relative (/...) unless the context used for executing the engine implements the .thymeleaf.context.IWebContext interface (template: "books" - line 5, col 26)
Please help me solve this problem. Thanks in advance
A ton of questions have been asked about connecting Thymeleaf + CSS and Spring Boot. I could not find any that addressed this problem with Ktor.
I have this template:
<!DOCTYPE html>
<html xmlns:th="; lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" th:href="@{/assets/css/style.css}">
</head>
<body>
...
</body>
</html>
This is what the file structure looks like:
src/main/resources/assets/css/style.css
src/main/resources/templates/thymeleaf/books.html
The templating plugin is set up in the following way:
fun Application.configureTemplating() {
install(Thymeleaf) {
setTemplateResolver(ClassLoaderTemplateResolver().apply {
prefix = "templates/thymeleaf/"
suffix = ".html"
characterEncoding = "utf-8"
})
}
}
This setup works fine without linking CSS, but when trying to link CSS, this error occurs:
.thymeleaf.exceptions.TemplateProcessingException: Link base "/assets/css/style.css" cannot be context relative (/...) unless the context used for executing the engine implements the .thymeleaf.context.IWebContext interface (template: "books" - line 5, col 26)
Please help me solve this problem. Thanks in advance
本文标签: htmlLink base quotassetscssstylecssquot cannot be context relative ()Stack Overflow
版权声明:本文标题:html - Link base "assetscssstyle.css" cannot be context relative (...) - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745648670a2161179.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论