Spring Boot 整合 JSP

本文详细介绍了如何在Spring Boot中整合JSP,包括JSP的底层原理和实际应用。JSP作为Java的动态网页技术,通过JSP引擎转化为Servlet处理。文章覆盖了从创建Maven Web项目,配置pom.xml,编写Handler,到使用JSTL的实际操作步骤。
摘要由CSDN通过智能技术生成

Spring Boot 整合 JSP

Spring Boot 与视图层的整合:
1、JSP
2、Thymeleaf
Java Server Page,是 Java 提供的⼀种动态网页技术,底层是 Servlet,可以直接在 HTML 中插⼊ Java代码。

JSP 底层原理:

JSP 是⼀种中间层组件,开发者可以在这个组件中将 Java 代码与 HTML 代码进行整合,由 JSP 引擎将组件转为 Servlet,再把开发者定义在组件中的混合代码翻译成 Servlet 的响应语句,输出给客户端。

1、创建基于 Maven 的 Web 项目,pom.xml

<parent>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-parent</artifactId>
 <version>2.2.4.RELEASE</version>
</parent> <dependencies>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-web</artifactId>
 <version>2.2.4.RELEASE</version>
 </dependency>
 <dependency>
 <groupId>org.apache.tomcat.embed</groupId>
 <artifactId>tomcat-embed-jasper</artifactId>
 <version>9.0.19</version>
 </dependency>
</dependencies>

2、创建 Handler

package com.southwind.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping("/hello")
public class HelloHandler {
   
 @GetMapping("/index")
 public ModelAndView index(){
   
 ModelAndView modelAndView = new ModelAndView();
 modelAndView.setViewName("index");
 modelAndView.addObject("mess","Hello Spring Boot");
 return modelAndView;
 }
}

3、JSP

<html> <head>
 <title>Title</title>
</head> <body>
 <h1>Index</h1>
 ${mess}
</body>
</html

4、application.yml

server:
 port: 8181
spring:
 mvc:
 view:
 prefix: /
 suffix: .jsp

5、Application

package com.southwind;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
   
 public static void main(String[] args) {
   
 SpringApplication.run(Application.class,args
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

走不尽的心路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值