I am an absolute noob when it comes to web development. But I got some background in C/C++/Java so I don't have a problem with MVC controllers. It's the configuration that is giving me the headache.
I am using Spring Boot. And according to the tutorials it can magically resolve everything without even opening an editor and typing a single character. Apparently not.
I have a view resolver configure as such:
@Configuration
@ComponentScan (basePackages = {"my.test.controller"})
@EnableAutoConfiguration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
@Bean
public InternalResourceViewResolver getViewResolver(){
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
public static void main(String[] args) throws Exception {
SpringApplication.run(WebConfig.class, args);
}
}
I have a controller like this:
@Controller
public class PageController {
@RequestMapping(value = "/index")
public String doSomething() {
//.. do Something
return "/index";
}
My main problem is it cannot find the file if there is a jsp extension in the address. If I type the url without an extension like localhost:8080/index the page is displayed properly. If I type the url with an extension like localhost:8080/index.jsp the page returns a 404 error. This is the same for all pages declared in the controller.
Any help will be greatly appreciated. Thanks thanks.