I have a similar problem as this JSP file not rendering in Spring Boot web application
But suggested answer is unfortunately not working for me.
I created project using start.spring.io service, and the default structure was
/src/main/java
/src/main/resources/templates
/src/main/resources/static
I have a JSP page called add.jsp
:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>Add</body>
</html>
which I tried to put in /src/main/resources/templates This was not working at all, then I created new folder webapp and put my jsp file there like this:
/src/main/webapp/WEB-INF/add.jsp
In browser (I tried Chrome and Safari) I get the contents of file, not
Add
Here is my code from configuration:
@Bean
public ViewResolver getViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/");
resolver.setSuffix(".jsp");
return resolver;
}
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
}
I have these dependencies in pom.xml
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>
</dependency>
Maybe I should put my jsp files in other folder or add other resolver? Thank you in advance for your suggestions!
UPDATE
If I add <!DOCTYPE html>
my jsp would partially work, but not in full, namely
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
is displayed, when it shouldn't. Where could the problem lie?