简体   繁体   English

加载资源失败:服务器响应状态为404() SpringBoot

[英]Failed to load resource: the server responded with a status of 404 () SpringBoot

I would like to call external javaScript function in my HTML.我想在我的 HTML 中调用外部 javaScript function。 When I open the local HTML file URL in Intellij Idea, the HTML will appear as expected.当我在 Intellij Idea 中打开本地 HTML 文件 URL 时,HTML 将按预期出现。 However, when I try to run the web application, the javaScript function will not appear.但是,当我尝试运行 web 应用程序时,不会出现 javaScript function。 When I press F12 on the webpage, it mentions:当我在网页上按 F12 时,它提到:

Failed to load resource: the server responded with a status of 404 () for the script.js.加载资源失败:服务器响应 script.js 的状态为 404 ()。

I tried to use the absolute path for my javaScript file but the same problem persists.我尝试对我的 javaScript 文件使用绝对路径,但同样的问题仍然存在。 May I know how do I fix this?我可以知道如何解决这个问题吗? Below are my HTML file:下面是我的 HTML 文件:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>New Employee Form</title>
    <link rel = "stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
          integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
          crossorigin="anonymous">
    <style>
       form {
         text-align: center;
         padding: 40px 0;
         background: #EBF0F5;
        }

    </style>
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.js" ></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.5/jquery.validate.js"></script>
    <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.5/additional-methods.js"></script>
    <script type="text/javascript" src="script.js"></script>

</head>
<body>

<div class="container">
    <h1 style="text-align:center;">New Employee Form</h1>
    <hr>
    <h2 style="text-align:center;">Save Employee</h2>

    <div id="ERRORS"> </div>
    <form  id="form" action="#" th:action="@{/saveEmployee}" th:object="${employee}"
          method="POST">
        <span class="error_form" id="fname_error_message"></span>
        <input id="firstName" name="firstName" type="text" th:field="*{firstName}"
               placeholder="Employee First Name" class="form-control mx-auto col-8 mb-3"  >

        <span class="error_form" id="lname_error_message"></span>
        <input id="lastName" name="lastName" type="text" th:field="*{lastName}"
               placeholder="Employee Last Name" class="form-control mx-auto col-8 mb-3" >

        <span class="error_form" id="email_error_message"></span>
        <input id="email" name="email" type="email" th:field="*{email}"
               placeholder="Employee Email" class="form-control mx-auto col-8 mb-3" >

      <br>

        <button type="submit " class="btn btn-info col-2"> Save Employee</button>

    </form>

    <a th:href = "@{/employeeList}" class="btn btn-info col-2 "> View Employee</a>
    <hr>
</div>

</body>
</html>

Below is where I save my HTML and javascript file.下面是我保存 HTML 和 javascript 文件的位置。 资源

you could try to move the script.js file into the directory of the project to fix the issue or you could try just copying javascript code straight into HTML in the <script></script> tag.您可以尝试将script.js文件移动到项目目录中以解决问题,或者您可以尝试将javascript代码直接复制到<script></script>标记中的HTML中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 加载资源失败:服务器响应状态为 404() - Failed to load resource: the server responded with a status of 404 () 加载资源失败:服务器响应状态为404 - Failed to load resource: the server responded with a status of 404 无法加载资源:服务器响应状态为404? 资源问题 - Failed to load resource: the server responded with a status of 404 ? Resource issue 程序无法加载无法加载资源:服务器以404(未找到)状态响应 - Program will not load Failed to load resource: the server responded with a status of 404 (Not Found) Node.js服务器:无法加载资源:服务器以状态404(未找到)响应 - Nodejs server: Failed to load resource: the server responded with a status of 404 (Not Found) 加载资源失败:服务器响应状态为 404(未找到)? - Failed to load resource: the server responded with a status of 404 (Not Found)? 加载资源失败:服务器响应状态为404(未找到) - getting Failed to load resource: the server responded with a status of 404 (Not Found) 加载资源失败:服务器响应状态为404()Controller.js:1 - Failed to load resource: the server responded with a status of 404 () Controller.js:1 AngularJS-$ http加载资源失败:服务器响应状态为404 - AngularJS - $http Failed to load resource: the server responded with a status of 404 Angular.js库无法加载资源:服务器响应状态为404(未找到) - Angularjs libs Failed to load resource: the server responded with a status of 404 (Not Found)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM