I am using spring boot simple application for displaying a JSP. However instead of rendering the JSP the page gets downloaded in the browser. Please suggest?
You are missing the JEE dependency.
javax
javaee-web-api
7.0
provided
Also, I highly suggest that you put all your JSP into your WEB-INF folder (this is true for any templating engine) and choose a prefix other than root. It's just more secure and more flexible if you also want to have some RESTlike endpoints served from the same application.
You can also extend the WebMvcConfigurerAdapter and override applicable methods.
// Add the JSP view resolver.
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.jsp();
// OR
registry.jsp("/",".jsp");
}
//... snip
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry
.addViewController("/yourpath")
.setViewName("yourtemplate");
}
"addViewControllers" is nice to use so you don't have to create a controller for each generic JSP and partial. Notice that I did not add ".jsp" to the view name.
You can use the root context as the prefix and still use the above configuration.