【问题标题】:Unable to link css to JSP page无法将 css 链接到 JSP 页面
【发布时间】:2016-09-25 08:55:38
【问题描述】:

我无法将 css 链接到 JSP 页面 -

项目结构:

webapp
  resources
    css      
      bootstrap-iso.css
  WEB-INF    
    views
      jsp
        app.jsp

jsp文件中的以下代码有效:

<link rel="stylesheet" href="https://formden.com/static/cdn/bootstrap-iso.css"/>

但是,当我给出以下任何一个时它都不起作用

<link rel="stylesheet" href="../../../resources/css/bootstrap-iso.css"/>
<link rel="stylesheet" href="/resources/css/bootstrap-iso.css"/>

我还在 ApplicationConfig 文件中设置了资源处理程序

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}

【问题讨论】:

    标签: css spring jsp spring-mvc


    【解决方案1】:

    尝试在spring-web-config.xml文件中配置资源:

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

    并将css文件与c:url链接:

    <link href="<c:url value="/resources/css/bootstrap-iso.css" />" rel="stylesheet">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-21
      • 2022-01-21
      • 2013-12-13
      • 1970-01-01
      • 2014-02-04
      • 2018-10-06
      • 1970-01-01
      相关资源
      最近更新 更多