springboot怎么加载jsp
时间: 2023-06-28 07:09:10 浏览: 114
在 Spring Boot 中,使用 JSP 需要进行如下配置:
1. 添加对 tomcat-embed-jasper 的依赖:
```xml
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
```
2. 在 application.properties 文件中配置 JSP 相关的属性:
```properties
# 设置 JSP 目录
spring.mvc.view.prefix=/WEB-INF/jsp/
# 设置 JSP 后缀
spring.mvc.view.suffix=.jsp
# 禁用 Thymeleaf 模板引擎,避免冲突
spring.thymeleaf.enabled=false
```
3. 在 Spring Boot 启动类上添加 @EnableWebMvc 注解:
```java
@SpringBootApplication
@EnableWebMvc
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
```
4. 将 JSP 文件放置在 /src/main/webapp/WEB-INF/jsp/ 目录下。
这样就可以通过访问相应的 Controller 返回 JSP 页面了。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](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)
![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)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)