spring 和 apache 磁贴中 css 文件的错误 url

发布于 2024-12-23 16:10:30 字数 234 浏览 4 评论 0原文

我正在创建基于 spring 和 apache 磁贴的 REST 应用程序。我添加了 .css 文件,在主页上它可以正常工作。我的意思是,当我在 domain.com/ 上时,但是当我转到 domain.com/something/ 时,网址是相同的,而且是错误的。我必须在 .css 文件路径的开头添加 ../

如何在每个子页面上创建(自动)正确的文件路径?

I'm creating REST application based on spring and apache tiles. I've added .css file and on main page it work everything. I mean when I'm on domain.com/ but when I'll go to domain.com/something/ the url is the same and it's wrong. I would have to add ../ at the start of .css file path

How can I create (by auto) correct file path on every subpage ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

謌踐踏愛綪 2024-12-30 16:10:30

使用绝对路径而不是相对路径:

href="/css/someFile.css"

而不是

href="css/someFile.css"

您还必须确保 Web 应用程序的上下文路径始终放在前面,因此该路径实际上应该是

href="${pageContext.request.contextPath}/css/someFile.css"

or,如果您使用 JSTL:

href="<c:url value='/css/someFile.css'/>"

Use absolute paths rather than relative paths:

href="/css/someFile.css"

rather than

href="css/someFile.css"

You must also make sure that the web app's context path is always prepended, so the path should in fact be

href="${pageContext.request.contextPath}/css/someFile.css"

or, if you use the JSTL:

href="<c:url value='/css/someFile.css'/>"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文