我有一个 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/