404尝试从Tomcat中的jsp链接到css文件时

时间:2015-10-21 20:53:26

标签: css jsp tomcat

我正在尝试将我的css文件(styles.css)链接到我的jsp文件(login.jsp),但是使用带有链接标记的html,我无法链接css!任何sugestions?我确定我正确地放置了路径,因为我使用了css文件(使用jsp表达式导入),我可以从login.jsp中读取它。似乎链接标记不适用于jsp。我有很多类似我的问题,但解决方案对我来说从来没有用过。

这是我项目的结构:

structure

我的jsp文件头,

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Authenticator</title>
<link rel="stylesheet" type="text/css" href="/css/styles.css">

</head>

谢谢, 罗德里戈

1 个答案:

答案 0 :(得分:2)

一个tomcat服务器可以同时包含多个项目。除了名为ROOT的项目之外的所有项目都将作为localhost:8080/your-project提供。因此,您可以使用以下链接指令来访问您的css文件:

<!-- for use from everywhere using an absolute path -->
<link rel="stylesheet" href="/your-project/css/styles.css">

<!-- for use from a specific directory (in this case
     from the project's root) using an relative path -->
<link rel="stylesheet" href="css/styles.css">

此外,您可能需要将jsp文件放在WEB-INF文件夹之外,有关详细信息,请参阅the docs