How to add a JSP page into Spring boot web application

I generate a sprint boot by https://start.spring.io/. Then I added a JSP view to the project. But it is not rendering. I don't know what could be wrong. Here is my project code:-

Main App:-

@SpringBootApplication

public class Application {

public static void main(String[] args) {

ApplicationContext ctx = SpringApplication.run(Application.class, args);

}

}

Configuration:-

@Configuration

@EnableWebMvc

public class MvcConfiguration implements WebMvcConfigurer {

@Bean

public ViewResolver getViewResolver() {

InternalResourceViewResolver resolver = new InternalResourceViewResolver();

resolver.setPrefix("/WEB-INF/");

resolver.setSuffix(".jsp");

return resolver;

}

@Override

public void configureDefaultServletHandling(

DefaultServletHandlerConfigurer configurer) {

configurer.enable();

}

}

Controller:-

@Controller

public class HelloController3 {

@RequestMapping("/hello")

public String hello(Model model, @RequestParam(value="name", required=false, defaultValue="World") String name) {

model.addAttribute("name", name);

return "hello";

}

}

I have my hello.jsp file located at /WEB-INF/ directory. What am I missing? It...

Read More »

By: StackOverFlow - Tuesday, 13 March

Related Posts