Spring Boot Controller 返回jsp页面结果返回404错误
Spring Boot Controller 返回jsp页面结果404
例如:
@Controller
public class LoginBackController {
public LoginBackController() {
// TODO Auto-generated constructor stub
}
@RequestMapping("/loginback")
public String index(Map<String,Object> map){
map.put("name", "HelloController");
return "loginback";
}
}
在 return "loginback";
一行下断点是可以命中的,
但是浏览器访问却返回 404 错误。
这是因为缺少依赖项,
在 pom.xml 中添加以下依赖:
pom.xml加入支持jsp的依赖
<!-- servlet依赖. -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- JSTL(JSP Standard TagLibrary,JSP标准标签库)是一个不断完善的开放源代码的JSP标签库,是由apache的jakarta小组来维护的。JSTL只能运行在支持JSP1.2和Servlet2.3规范的容器上,如tomcat
4.x。在JSP2.0中也是作为标准支持的。 不然报异常信息: javax.servlet.ServletException:Circular view
path [/helloJsp]: would dispatch back to the current handler URL[/helloJsp]
again. Check your ViewResolver setup! (Hint: This may be the resultof an
unspecified view, due to default view name generation.) -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- Provided -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>