我使用"spring tool suite“创建了spring boot starter项目。当我运行项目时,无法加载index.jsp页面。但是index.html可以很好地加载。
我的文件夹结构如下

我的家庭控制器是
package com.programmingfree.springservice;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping("/")
public String home() {
return "index";
}
}如何运行index.jsp
发布于 2017-12-18 18:05:17
您正在使用spring boot的默认配置,请看ThymeleafProperties.java,.html是后缀的默认设置:
@ConfigurationProperties(
prefix = "spring.thymeleaf"
)
public class ThymeleafProperties {
private static final Charset DEFAULT_ENCODING = Charset.forName("UTF-8");
private static final MimeType DEFAULT_CONTENT_TYPE = MimeType.valueOf("text/html");
public static final String DEFAULT_PREFIX = "classpath:/templates/";
public static final String DEFAULT_SUFFIX = ".html";
private boolean checkTemplate = true;
private boolean checkTemplateLocation = true;
private String prefix = "classpath:/templates/";
private String suffix = ".html";
private String mode = "HTML5";
//......
}所以你必须在application.properties中自定义你的配置:
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.jsp发布于 2017-12-18 18:05:41
你在application.properties中有下一行吗?
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp由于为胸腺叶和FreeMarker自动配置的ResourceUrlEncodingFilter,到资源的链接在运行时会在模板中重写。在使用JSP时,您应该手动声明此过滤器。spring doc
https://stackoverflow.com/questions/47865550
复制相似问题