Spring Boot中访问JSP页面,首先确保你已经添加了Thymeleaf或JSTL依赖到你的项目。以下是一个简单的例子,展示如何在Spring Boot应用中配置和访问一个JSP页面。

1. 添加依赖

spring booot 访问jsp实例,SpringBoot访问JSP实例  第1张

在`pom.xml`文件中添加以下依赖(以Thymeleaf为例):

```xml

org.springframework.boot

spring-boot-starter-thymeleaf

```

2. 配置文件

在`application.properties`或`application.yml`文件中配置视图模板的路径:

```properties

spring.thymeleaf.prefix=classpath:/templates/

spring.thymeleaf.suffix=.html

spring.thymeleaf.mode=HTML

```

如果你使用JSTL,则不需要修改`suffix`,因为它默认就是`.jsp`。

3. 创建控制器

在Spring Boot应用中创建一个控制器来处理请求并返回JSP页面:

```java

@SpringBootApplication

public class SpringBootJspApplication {

public static void main(String[] args) {

SpringApplication.run(SpringBootJspApplication.class, args);

}

@RestController

public class JspController {

@GetMapping("