SpringBoot跳转jsp页面

SpringBoot跳转jsp页面


前言

想要的结果:
在这里插入图片描述

一、配置pom.xml

		<!--切记,此处的模板引入要注释掉,跳转到jsp页面并不需要它-->
		<!-- <dependency>
		  <groupId>org.springframework.boot</groupId>
		  <artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency> -->
		 
		 
		<!-- jsp -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>

二、配置application.properties文件

#springmvc
spring.mvc.view.prefix:/WEB-INF/
spring.mvc.view.suffix:.jsp

三、创建存放jsp的文件夹

main–>webapp–>WEB-INF -->(此处也可以创建下级目录,但是要在application.properties文件的spring.mvc.view.prefix:/WEB-INF/这行代码进行配置)

并且创建测试页面
在这里插入图片描述

四、创建Controller类

@Controller
@RequestMapping("/authToExamine")
public class AuthToExamineController {
	@RequestMapping("/authToExamineList")
	public String authToExamineList(){
		//return "authToExamineList";
		return "index";
	}
}

五、测试

输入您的接口地址:我的为http://localhost:8888/authToExamine/authToExamineList

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
springboot中使用Thymeleaf模板引擎来实现跳转jsp页面。 首先,确保在pom.xml文件中引入了Thymeleaf以及Spring Boot相关的依赖。然后在application.properties文件中配置Thymeleaf的相关属性。 接下来,在Spring Boot的Controller中定义一个请求处理方法,使用@GetMapping或@PostMapping注解来映射URL路径。在方法中,通过返回一个字符串类型的视图名称来实现跳转。 例如,假设我们有一个UserController类,其中有一个方法用于处理"/user"路径的请求: ```java @Controller public class UserController { @GetMapping("/user") public String showUser(Model model) { // 处理业务逻辑,将数据存入model对象中 model.addAttribute("username", "John Doe"); return "user"; // 返回user作为视图名称 } } ``` 注意,跳转jsp页面的名称应与返回的视图名称对应。同时,该jsp文件需要保存在src/main/resources/templates目录下。 在jsp页面中,可以使用Thymeleaf的语法来显示从Controller传递的数据。例如,在user.jsp中可以使用如下代码显示用户名: ```html <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <title>User Page</title> </head> <body> <h1>Welcome, <span th:text="${username}"></span>!</h1> </body> </html> ``` 在浏览器中访问"/user"路径,就可以看到跳转到user.jsp页面并显示用户名的效果。 通过上述步骤,我们就可以在Spring Boot中使用Thymeleaf模板引擎来实现跳转jsp页面

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值