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

标签 javascript css spring maven

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

相关文章:

java - 将 Spring 任务 XML 配置转换为代码配置

javascript - 仅通过单击特定元素的按钮更改样式表

javascript - 如何在同一行将不同的语言更改为不同的字体大小而无需每个容器都是唯一的?

css - 如何在非图像元素上使用图像上下文菜单?

java - Spring应用程序上下文: access web. xml上下文参数?

spring - 如何更改grails中的约束错误消息

javascript - jscript 如何查找当前 url 并重定向 + QueryString

javascript - 无法访问类构造函数中设置的变量

javascript - 语义 UI 搜索和本地搜索不起作用

javascript - 调用函数时在javascript中设置计时器