版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36688143/article/details/82015183
SpringBoot执行ajax跳转到jsp
1、pom.xml中添加jsp支持
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<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执行ajax跳转到html
1、springboot推荐使用thymeleaf,所以在pom.xml中添加thymeleaf模板jar
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2、application.yml中配置返回值前缀后缀
spring:
mvc:
view:
prefix: /templates/
suffix: .html
注意:这样子的html文件标签必须是严格的,否则运行时就会报错缺少某一部分闭合标签
解决办法:下面这里是抄人家的,懒得自己改了,反正方法一样,来源:点击打开
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>