springboot整合jsp时jsp404问题

如题,在学习springboot整合jsp页面时,发现配置了如下配置

spring.mvc.view.prefix=/WEB-INF/view/

spring.mvc.view.suffix=.jsp

 调试页面会出现页面找不到的情况。报错大致为:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Thu Apr 21 00:44:20 CST 2022

There was an unexpected error (type=Not Found, status=404).

No message available

 

网上各种方案,包括edit configurations下添加working directory,还是configuration类里面添加如下方法:

@Bean public WebServerFactoryCustomizer<TomcatServletWebServerFactory> customizer() { return (factory) -> { factory.addContextCustomizers(context -> { String relatePath = "src/main/webapp"; context.setDocBase(new File(relatePath).getAbsolutePath()); }); }; } 

都是不行的。但是我debug,发现到了我的controller里面了,而且最后console还打印了页面地址:

Path with "WEB-INF" or "META-INF": [WEB-INF/view/page.jsp]。 

依然找了各种答案,最后看到一个文章说springboot默认不使用jsp,需要在pom.xml中引用jsp的编译程序。然后我引入了依赖项,重新编译启动后顺利成功。

依赖项如下:

<!--jsp页面使用jstl标签 --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <!--用于编译jsp --> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> 

任何一个小细节都可能导致失败呀。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值