javaspringspring-bootjsp

.jsp file not found in Spring Boot webapp


So, yesterday I was working on deploying a webapp in spring boot with JSP and everything was working fine, then I had to pull some commits from remote and it stopped working and displaying the error below when accessing http://localhost:8080/

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.

Mon Feb 15 10:35:53 WET 2021 There was an unexpected error (type=Not Found, status=404). JSP file [/WEB-INF/views/index.jsp] not found

I didn't change any setting and I don't know what is happening, everything appears to be in the correct directory and with the correct settings

HomeController at \src\main\java\projectName\Controllers

    @Controller
    public class HomeController {
    
        @GetMapping(value = "/")
        public String homePage() {
            return "index";
        }
    }

application.properties

spring.mvc.view.suffix=.jsp
spring.mvc.view.prefix=/WEB-INF/views/

index.jsp at \src\main\webapp\WEB-INF\views\

I have searched everything I can online, but it leads me always to the same pointers, all my directories appear to be correct and this has worked before with these settings so I don't know why it suddenly stopped working


Solution

  • Ok so for whoever has the same issue. I have solved it.

    My project structure was as follow

    main-directory           <---- Content from original repo (not a java project)
    --java-project-directory <----- JAVA project created here
    ----src
    ------main
    --------webapp
    ----------WEB-INF
    ------------view
    --------------index.jsp
    

    I was opening the project with my IDE directly on the main-directory, I could still run the project fine and it compiled without errors, however this caused the HTML server or JSP to mess up the pathing because the root directory was different. So the .jsp files (which were correctly set up) were never found.

    By opening the project on my IDE directly from java-project-directory I was able to get .jsp and all the pages working correctly. Presumably, because it assumed the correct path.