简体   繁体   English

Spring Boot项目运行问题

[英]spring boot project running issue

I created spring boot starter project using "spring tool suite". 我使用“ spring工具套件”创建了spring boot启动程序项目。 when i am running project, index.jsp page not loading. 当我正在运行项目时,index.jsp页面无法加载。 but index.html can load nicely. 但index.html可以很好地加载。

my folder structure as below 我的文件夹结构如下

在此处输入图片说明

my home controller is 我的家庭控制器是

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";
    }

}

how i run index.jsp 我如何运行index.jsp

You are using the default configuration for spring boot, take a look at ThymeleafProperties.java , .html is the default setting for suffix: 您正在使用默认配置进行春季启动,请查看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";
    //......
}

So you have to customize your config in application.properties: 因此,您必须在application.properties中自定义配置:

spring.thymeleaf.prefix=classpath:/templates/  
spring.thymeleaf.suffix=.jsp

Do you have next lines in application.properties? 在application.properties中是否有下一行?

spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp

Links to resources are rewritten at runtime in template, thanks to a ResourceUrlEncodingFilter, auto-configured for Thymeleaf and FreeMarker. 通过为Thymeleaf和FreeMarker自动配置的ResourceUrlEncodingFilter,可以在运行时在模板中重写到资源的链接。 You should manually declare this filter when using JSPs. 使用JSP时,您应该手动声明此过滤器。 spring doc 春季文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM