Reputation: 780
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
Upvotes: 2
Views: 4936
Reputation: 1
HTTP Status 404 – Not Found Type Status Report
Message JSP file [/WEB-INF/viewsindex.jsp] not found
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
solution in spring-servlet.xml give this path /WEB-INF/views/
Upvotes: 0
Reputation: 11
I had the same error and applied many answers (of course one by one), including the answers posted on this page. None of them brought resolution to the 404 Not Found (White Label error). Finally, I identified that my package naming parts (the parts separated by the intervening . (period) had inconsistency (com.msoftgp.springboot and com.msoftgp.springbootmvc.controller). Once I made them to be same and ran the application and sent a request, the response came correctly with the home page showing up on the browser. All my carelessness not to pay attention to stick with consistent package structure.
Upvotes: 0
Reputation: 780
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.
Upvotes: 2
Reputation: 710
@Controller
public class HomeController {
@GetMapping(value = "/") <<< Try @RequestMapping("/")
public String homePage() {
return "index";
}
}
Upvotes: 0