gpt4 book ai didi

javascript - Spring maven ,访问 CSS/JS 文件

转载 作者:行者123 更新时间:2023-11-30 10:38:56 25 4
gpt4 key购买 nike

我有一个 Spring 元素:

资源文件位于:src/main/resources/style/.........很多子文件夹

servlet.xml:

    <mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/resources/" />

和我的jsp:

<link rel="stylesheet" href="<%=request.getContextPath()%>/resources/style/jquery_ui/css/custom-theme/jquery-ui-1.8.23.custom.css"/>

当我浏览到我的 View 时,将此链接作为位置:

http://localhost:8080/webapp/WEB-INF/classes/style/jquery_ui/css/custom-theme/jquery-ui-1.8.23.custom.css

如何让它正确显示 css 文件?

最佳答案

标准 Maven 布局具有位于 src/main/webapp/resources 中的 Web 资源。 src/main/resources 更多用于库和 Java 资源。

使用 JSTL core 可以轻松地在 JSP 中引用它们c:url tag .使用这些时,您无需担心上下文根。例如:

<link rel="stylesheet" href="<c:url value="/resources/style/jquery_ui/css/custom-theme/jquery-ui-1.8.23.custom.css" />" />

库会自动将上下文根添加到此 URL。

关于javascript - Spring maven ,访问 CSS/JS 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12333020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com