1

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?

zb226
  • 9,586
  • 6
  • 49
  • 79
lenach87
  • 949
  • 3
  • 11
  • 18
  • 1
    Read this, and follow the example. http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-jsp-limitations – JB Nizet Apr 14 '16 at 21:40
  • Thank you for your answer! I followed the example in full and it helped! – lenach87 Apr 14 '16 at 21:58
  • Sorry, I was happy too early. My jsp is only partially displayed. But for example this part is for some reason shown on the page <%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8"%> – lenach87 Apr 15 '16 at 14:26
  • Try this [Demo](https://github.com/RawSanj/SOFRepos/tree/master/Spring-Boot-Jsp-Demo). Also see this [QnA](http://stackoverflow.com/questions/36110386/spring-boot-mvc-not-using-model-values-in-jsp?answertab=votes#tab-top). – Sanjay Rawat Apr 15 '16 at 21:21
  • Thank you! The QnA is the same as mine, but dependency issue didin't help me. I created new project with Spring Boot - 1.4.0.M2 - still no luck. But I will try to search further in dependencies issue – lenach87 Apr 15 '16 at 22:39
  • Have you tried this [Demo](https://github.com/RawSanj/SOFRepos/tree/master/Spring-Boot-Jsp-Demo)? Its based on Boot 1.3.3. – Sanjay Rawat Apr 19 '16 at 20:34

0 Answers0