我有一个 j2ee 应用程序,我正在构建并部署到 gae,出于某种原因,当我的 url 末尾有一个尾部斜杠时,CSS 不会加载。
例如:
mysite.com/account
完美运行
但
mysite.com/account/
加载没有 CSS 的页面
知道我能做些什么来解决这个问题吗?
CSS 样式表:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="/css/rrstyles.css" rel="stylesheet">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/grayscale.css" rel="stylesheet">
<link href="font-awesome-4.2.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<title>My app</title>
</head>
我将这个标头作为单独的 jsp 包含在内,但是当我转到/account 而不是/account/时,由于某种原因,它可以工作。我不明白这是怎么回事。
大多数 CSS 链接都有相对 URL。这意味着它们将相对于调用页面的 URL 目录进行解释。当调用方 URL mysite.com/account
时,URL css/grayscale.css
被解释为 mysite.com/css/grayscale.css
。但是当调用方URL被mysite.com/account/
时,CSS URL被视为mysite.com/account/css/grayscale.css
。
最简单的解决方案是在 URL 中使用绝对路径:
<link href="/css/grayscale.css" rel="stylesheet">
它将 100% 工作
步骤 1
<mvc:resources location="/WEB-INF/assets/" mapping="/resources/**"></mvc:resources>
系列2
<spring:url var="css" value="/resources/css/"/>
<spring:url var="js" value="/resources/js/"/>
<spring:url var="image" value="/resources/image/"/>
在值后添加斜杠
步骤 3
像这样添加样式表
<link rel="stylesheet"
href="${css}/common/bootstrap.min.css">