英文:
Static content not loading from spring boot war in jboss server
问题
我已将静态内容,如CSS、JS和图像,放置在资源文件夹下的静态文件夹中,而将所有的HTML文件放置在模板文件夹中。然而,当我构建WAR文件并在JBoss上部署时,HTML被加载了,但静态内容没有被加载,在内置的Tomcat服务器中却能正常工作。
访问WAR文件页面的URL:IP:8080/warname/login
当我在Chrome的控制台中检查时,我得到JS、CSS的URL,如 IP:8080/js/jsfile.js
或者 IP:8080/css/abc.css
。
这是我的项目结构:
项目结构图片
英文:
i have placed the static content such as css, js , images in static folder under resources and all the html files in templates folder. however when i build a war and deploy it on jboss. the html is loaded but static content is not loaded and the same works fine in inbuild tomcat server.
url to access the war pages : IP:8080/warname/login
when i inspect in console of chrome i get url of js, css as IP:8080/js/jsfile.js
or IP:8080/css/abc.css
.
here is my project structure
image of project structure
答案1
得分: 0
你正在引用 src 或 href 中的静态内容,例如 /js,但是在部署为 WAR 文件时,这样做是行不通的,因为在应用服务器中会添加上下文根(在你的情况中是 warname)。
你需要使用 Thymeleaf 语法,像这样:
<script type="text/javascript" th:src="@{/js/searchOP.js}"></script>
请查阅文档获取更多信息:https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html
英文:
You are referencing the static content in src or href with for example /js but this does not work when deploying as WAR file because in the app server there will be a context root added. (warname in your case)
You have to use Thymleaf syntax like
<script type="text/javascript" th:src="@{/js/searchOP.js}"></script>
Please checkout the documentation for more information: https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论