<!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


javascript - 在JSP中添加CSS时出错-LMLPHP

最佳答案

您可以通过以下方式将您的css和scripts文件夹移动到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>

08-15 16:08
查看更多