Answer the question
In order to leave comments, you need to log in
How to properly configure jsp mapping in SpringBoot?
Hello. I am writing a simple mvc application on Spring Boot. I've run into a problem that I can't find a solution for. Please help.
All three mvc modules are written in the project. Problems arise with view.
There is a controller
@RequestMapping(value = "/", method = RequestMethod.GET)
public String homePage() {
return "hello";
}
@Configuration
@EnableWebMvc
public class AppConfiguration extends WebMvcConfigurerAdapter {
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setViewClass(org.springframework.web.servlet.view.JstlView.class);
resolver.setPrefix("/WEB-INF/");
resolver.setSuffix(".jsp");
return resolver;
}
// @Override
// public void addResourceHandlers(ResourceHandlerRegistry registry) {
// registry.addResourceHandler("/WEB-INF/").addResourceLocations("/css/");
// }
@Bean
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
registrationBean.setFilter(characterEncodingFilter);
return registrationBean;
}
}
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>Success!!!</h1>
</body>
</html>
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Jan 10 15:34:42 MSK 2017
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/hello.jsp
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question