SpringBoot执行请求跳转到jsp和跳转到html方法和html标签不严格问题解决

SpringBoot执行请求跳转到jsp

1、pom.xml中添加jsp支持

<dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <!-- 不要加provided,使用默认的compile,否则就会找不到页面
                 如果加provided,就需要添加tomcat、servlet包 -->
            <!--<scope>provided</scope>-->
        </dependency>

2、application.yml中配置返回值前缀后缀

注意:1、在springboot项目中,jsp文件的存放位置,默认为:src/main/webapp,而生成的springboot项目又是没有webapp这个文件夹的,所以需要自己新建该文件夹,并把jsp都放在里面

2、这里的前缀prefix不管配置什么,都是在src/main/webapp下的,我这里配“/”,意思就是src/main/webapp/index.jsp。如果配“/static/”,那你的jsp位置就是src/main/webapp/static/index.jsp

spring:
    mvc:
        view:
          prefix: /        
          suffix: .jsp

 

 

SpringBoot执行请求跳转到html

1、springboot推荐使用thymeleaf,所以在pom.xml中添加thymeleaf模板jar

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

建议在配置的路径前面加上classpath 

2、application.yml中配置返回值前缀后缀

spring:
    thymeleaf:
       prefix: classpath:/templates/
       suffix: .html

注意:这样子的html文件标签必须是严格的,否则运行时就会报错缺少某一部分闭合标签

如:元素类型<meta>不匹配啥啥的

解决办法:下面这里是抄人家的,懒得自己改了,反正方法一样,来源:点击打开

 

3、在application.properties中增加

spring.thymeleaf.content-type=text/html 
spring.thymeleaf.cache=false 
spring.thymeleaf.mode =LEGACYHTML5
  •  

即声明thymeleaf使用非严 格的html。启动之后访问页面会报如下错误:

 Cannot perform conversion to XML from legacy HTML: The nekoHTML library is not in classpath. nekoHTML 1.9.15 or newer is required for processing templates in "LEGACYHTML5" mode [http://nekohtml.sourceforge.net]. Maven spec: "net.sourceforge.nekohtml::nekohtml::1.9.15". IMPORTANT: DO NOT use versions of nekoHTML older than 1.9.15.

修改pom.xml 添加以下依赖 
 

<dependency> 
<groupId>net.sourceforge.nekohtml</groupId> 
<artifactId>nekohtml</artifactId> 
<version>1.9.22</version> 
</dependency>

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值