springboot集成jsp
时间: 2023-09-15 16:23:04 浏览: 166
在Spring Boot中集成JSP需要进行以下步骤:
1. 在pom.xml文件中添加以下依赖:
```xml
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
```
2. 在application.properties配置文件中添加以下配置:
```properties
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
```
3. 在src/main/webapp/WEB-INF目录下新建views文件夹,并在该文件夹下创建JSP文件。
4. 在Controller中添加RequestMapping并返回对应的JSP文件:
```java
@Controller
public class HomeController {
@RequestMapping("/")
public String home() {
return "home";
}
}
```
5. 启动应用程序并访问对应的URL即可访问JSP页面。
注:在Spring Boot 2.4.x版本之后,不再支持JSP视图解析器。如果需要使用JSP,需要使用Tomcat作为嵌入式Servlet容器,并在application.properties中添加以下配置:
```properties
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
server.servlet.register-default-servlet=true
```
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)