javascript - jsp中添加css报错

标签 javascript html css jsp

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="../scripts/angular.min.js"></script>
<script type="text/javascript" src="../scripts/jquery-3.2.0.js"></script>
<link rel="stylesheet" type="text/css" href="../css/home.css">
<title>Hello</title>
</head>
<body>
    <div id="d1">
    asfsdg
    </div>

</body>
</html>

我正在尝试向 jsp 页面中的 html 元素添加样式,但是当我添加样式并在 tomacat 9.0 上运行它时,那里没有任何反应,只出现纯文本。 当我转到页面源并单击指向 css 的链接时,它显示了一个错误

HTTP Status 404 – Not Found

Type Status Report

Message /TutorNextDoor/css/home.css

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/9.0.0.M18

enter image description here

最佳答案

您可以将您的 css 和脚本文件夹移动到 Webcontent 中,并按照以下方式在 html/jsp 文件中提供路径:

 <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <!-- Scripts -->
    <script type="text/javascript" src="<%=request.getContextPath()%>/scripts/angular.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/scripts/jquery-3.2.0.js"></script>
    <!-- CSS -->
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/home.css">
    <title>Hello</title>
    </head>
    <body>
         <div id="d1">
            asfsdg
         </div>
    </body>
    </html>

关于javascript - jsp中添加css报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43235755/

相关文章:

css - 两个 div 到另一个 div,都具有可变大小

javascript - 或者比较不起作用?

javascript - 如何使用 native react 在手机中获取当前语言设置

javascript - 将函数调用存储在数组中

javascript - 在 IE5 怪异模式下更改 iframe 的 src 会导致整个页面发生变化

html - 语义网是否使用 XML 而不是 HTML 或 JSON?

html - 具有子跨度的 100% 宽度 div 不会右对齐

jquery - 根据元素数量布置 HTML 元素

javascript - ReactJS - 有条件地渲染空白

html - 简单的 CSS 给 IE 9 带来麻烦