0

I'm having an strange issue with using the index.html through a spring boot java controller, which has a method like this:

@GetMapping("/welcome") public String welcome() { return _index; }

where _index is defined as the file name:

private final String _index = "index.html";

I am also having a @Controller annotation above the class signature.

When I'm entering the /welcome endpoint, it gives a 404 error, but it should work when it returns a string of the existing file. Is there something I'm doing wrong? Long time since I did it like this.

My index.html uses javascript, that renders the content

    <!DOCTYPE html>
<html lang="en">
<head>
    <!-- Generated by JavaScript -->
    <div id="head_content"></div>
</head>
<body>
    <header>
        <!-- Generated by JavaScript -->
        <div class="wrapper">
            <div id="header_content"></div>
        </div>
    </header>
    <main>
        <!-- Generated by JavaScript -->
        <div class="wrapper">
            <div id="main_content"></div>
        </div>
    </main>
    <footer>
        <!-- Generated by JavaScript -->
        <div class="wrapper">
            <div id="footer_content"></div>
        </div>
    </footer>

    <script src="../static/javascripts/url.js"></script>

    <script src="../static/javascripts/logics/liszt.js"></script>
    <script src="../static/javascripts/logics/login.js"></script>
    <script src="../static/javascripts/logics/session/saves/saveUser.js"></script>
    <script src="../static/javascripts/logics/session/gets/getUser.js"></script>

    <script src="../static/javascripts/renderings/head_content_rendering.js"></script>
    <script src="../static/javascripts/renderings/header_content_rendering.js"></script>
    <script src="../static/javascripts/renderings/footer_content_rendering.js"></script>
    <script src="../static/javascripts/renderings/main_content_renderings/login_rendering.js"></script>
    <script src="../static/javascripts/renderings/main_content_renderings/main_content_rendering.js"></script>
</body>

</html>
Laustrup
  • 11
  • 4
  • What is your project structure? I believe the default location for a view would be under resources/templates – Josh Van de Walle Dec 19 '22 at 21:29
  • Thanks for the link @AbderKRIMA, Found out that I was silly and missed thymeleaf dependency in the pom.xml, thought that dependency was only meant for dynamic rendering of html and not using for the controller. – Laustrup Dec 20 '22 at 08:49

0 Answers0