是否可以在 Spring MVC JSP 文件中使用 Google 字体?

Is it possible to use Google Fonts in a Spring MVC JSP file?

我尝试将 link 添加到 JSP 文件头部的样式表中,并尝试在我的项目样式表中使用 @import 选项。没有任何效果。我也找不到 webjar 或任何类似的东西。

CSS:

@import url('https://fonts.googleapis.com/css?family=Boogaloo');

body {
    font-family: 'Boogaloo', cursive;
}

JSPF:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="<c:url value="/resources/css/main.css" />" rel="stylesheet">
    <link href="webjars/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Boogaloo" rel="stylesheet">

    <title>HappyLibs Emailer</title>
</head>

在使用 Google 字体方面,Spring MVC 或 JSP 没有任何特别之处。

根据我的经验,外部文件(如 css、javascript 和图像)通常位于 WebContent 文件夹(标准构建)或 webapp 文件夹(maven 构建)中。

我认为 c:url 标签对此没有必要。

标准示例[root]/WebContent/[任何有意义的文件夹结构]/main.css

MVN 示例src/main/webapp/[任何有意义的文件夹结构]/main.css

我正好喜欢这样的结构 -> /view/page/[特定页面]/[文件]

然后,在JSP:

<!DOCTYPE html >
<html>
     <head>
          ...
          <link href="https://fonts.googleapis.com/css?family=Boogaloo" rel="stylesheet">
          <link href="view/main.css" rel="stylesheet" >
          ...
     </head>
     <body>
          ...
     </body>
</html>

此外,如果在指定位置找不到文件,浏览器的开发人员工具应该会显示错误。

Chrome 开发者工具(即:右键单击页面并选择 'inspect'): 如果找不到它,控制台选项卡将显示错误。 Sources 选项卡将向您显示页面实际加载的文件。元素选项卡将指定应用于相关元素的样式 -> 以确保其他内容不会简单地覆盖您期望的样式。

找到了问题 - 它实际上是由我脑海中 link 的顺序引起的。我需要在 Bootstrap link 之后应用我的 CSS,这样我的样式就不会被覆盖:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="webjars/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Boogaloo" rel="stylesheet">
    <link href="<c:url value="/resources/css/main.css" />" rel="stylesheet" type="text/css">

    <title>HappyLibs Emailer</title>
</head>