首页  编辑  

SpringBoot Controller报错404

Tags: /Java/   Date Created:
Spring boot + JSP + @Controller注解返回页面的时候,如果提示下面的错误:

Whitelabel Error Page

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

Mon Oct 17 18:12:22 CST 2022
There was an unexpected error (type=Not Found, status=404).
No message available

那是因为缺少以下依赖包:
<!-- jsp的整合依赖 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
记得Maven  Sync 一下项目,否则还是不生效的。
@Controller
public class TestController {
@RequestMapping(value="/")
public String index(Model model, HttpServletResponse response) {
model.addAttribute("name","this is ok");
return "index";
}
}
当然,不要忘记在 /src/main/webapp/WEB-INF/jsp目录下,放上你的jsp文件。