0

I've tried the answers related to the question in stackoverflow. It did not work out.

Here is my project structure :

enter image description here

Controller: To render the index.html

@Controller
public class MainController {

    @RequestMapping(value="/",method = RequestMethod.GET)
    public String homepage(){
        System.out.println("Inside controller..");
        return "index";
    }
}

When i'm trying to hit the URL, it prints Inside controller.. but not rendering the index page. Tried using WebMvcConfigurerAdapter as well.

In browser, it displays some error like Whitelabel Error Page

Am I missing something out here?

4 Answers4

0

Check for errors in the browser console. 'X-Frame-Options' may be set to 'DENY' that may block html page to load in the browser.

This How to disable 'X-Frame-Options' response header in Spring Security? may help.

Jack
  • 165
  • 2
  • 10
0

Please check your project structure. Application, and other packages like model, controller etc. should be under the same package or on the same level. Also make sure there are no extra configuration on application.yml/properties file regarding "spring.thymeleaf.prefix".

Project Structure

Dharman
  • 30,962
  • 25
  • 85
  • 135
aza
  • 1
0

try using full name with extension like index.html

vikas
  • 58
  • 6
-3

I think you shouldn't return String. Try instead something like ModelAndView.

Vadym Dudnyk
  • 162
  • 3
  • Yes, you can do that but it's not necessary so this is not the problem. Here's an example : https://spring.io/guides/gs/serving-web-content/ – Mickael Feb 14 '18 at 11:13