Springboot(二)springboot之jsp支持
参考恒宇少年的博客:https://www.jianshu.com/p/90a84c814d0c
springboot内部对jsp的支持并不是特别理想,而springboot推荐的视图是Thymeleaf(在以后章节进行讲解),但是开发人员对jsp的应用得掌握,还是必不可少的。
本文目标:
整合springboot web项目支持jsp作为视图输出
一、使用IntelliJ IDEA 工具来构建项目(建项目时候要选中war包)
二、自动生成的ServletInitializer类介绍
实现SpringBootServletInitializer的子类需要重写一个configure方法,方法内自动根据LessontwoApplication.class的类型创建一个SpringApplicationBuilder交付给springboot框架来完成初始化运行配置。
三、配置springboot支持jsp
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.1.2.RELEASE</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <groupId>com.dyh</groupId>
- <artifactId>lesson_two</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>war</packaging>
- <name>lesson_two</name>
- <description>Demo project for Spring Boot</description>
- <properties>
- <java.version>1.8</java.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-tomcat</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <!--添加springboot对jsp支持-->
- <dependency>
- <groupId>org.apache.tomcat.embed</groupId>
- <artifactId>tomcat-embed-jasper</artifactId>
- </dependency>
- <!--servlet支持开启-->
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
- </dependency>
- <!--使用jstl标签-->
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>jstl</artifactId>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
- </project>
四、配置视图
我们必须按照jsp文件之前的文件目录风格,在/webapp/WEB-INF/jsp目录下。
1. 在main目录下创建webapp文件夹
2. 在webapp下创建jsp文件夹
3. 修改application.properties文件让springmvc支持视图的跳转目录指向为/main/webapp/jsp
五、controller层代码书写,请求127.0.0.1:8080/index,返回到index.jsp页面
- @Controller
- public class JspController {
- @RequestMapping(value = "/index",method = RequestMethod.GET)
- public String getJsp(){
- return "index";
- }
- }
六、创建Jsp页面,并测试
- <%@ page contentType="text/html;charset=UTF-8" language="java" %>
- <html>
- <head>
- <title>Title</title>
- </head>
- <body>
- 这是一个jsp页面
- </body>
- </html>
Springboot(二)springboot之jsp支持的更多相关文章
- SpringBoot学习:添加JSP支持
项目下载地址:http://download.csdn.NET/detail/aqsunkai/9805821 (一)pom中添加依赖: <!-- https://mvnrepository.c ...
- springboot(二).springboot整合logback用于日志输出
springboot整合logback用于日志输出 我们项目的基本框架已经完成,http请求已经可以访问,现在给我们的框架添加日志记录的功能并能将每天的记录记录到文件中去 在这里,我们使用logbac ...
- SpringBoot(二) -- SpringBoot配置
一.配置文件 SpringBoot可以使用两种类型的配置文件(文件名固定): application.properties application.yml 配置文件的作用就是来修改SpringBoot ...
- SpringBoot(二) SpringBoot核心配置文件application.yml/properties
我们都知道在Spring中有着application.xml文件对Spring进行相关配置,通过web.xml中的contextConfigLocation指定application.xml文件所在位 ...
- SpringBoot(二): SpringBoot属性配置文件 SpringBoot多环境配置文件 SpringBoot自定义配置文件
1.属性配置文件 一共分为两种,一种是键值对的properties属性配置文件,一种是yaml格式的配置文件 properties配置: 2.多环境配置文件 当我们的项目中有多套配置文件 比如开发的配 ...
- 搭建SpringBoot、Jsp支持学习笔记
Spring Boot 添加JSP支持 大体步骤: (1) 创建Maven web project: (2) 在pom.xml文件添加依赖: (3) ...
- springboot 2.0 整合 同时支持jsp+html跳转
springboot项目创建教程 https://blog.csdn.net/q18771811872/article/details/88126835 springboot2.0 跳转html教程 ...
- spring-boot(二)
学习文章来自:http://www.ityouknow.com/spring-boot.html web开发 spring boot web开发非常的简单,其中包括常用的json输出.filters. ...
- springboot(二):web综合开发
上篇文章介绍了spring boot初级教程:spring boot(一):入门篇,方便大家快速入门.了解实践Spring boot特性:本篇文章接着上篇内容继续为大家介绍spring boot的其它 ...
随机推荐
- Linux下9种优秀的代码比对工具推荐
大家好,我是良许. 在我们编写代码的时候,我们经常需要知道两个文件之间,或者同一个文件不同版本之间有什么差异性.在 Windows 下有个很强大的工具叫作 BeyondCompare ,那在 Linu ...
- 只需几行 JavaScript 代码,网页瞬间有气质了!
最近在网上闲逛,发现一个特别好玩的 JavaScript 库,叫 RoughNotation.干嘛用的呢?就是在网页上给文字加标注,比如下划线.方框.高亮文字背景等,不过是手写风格的!截图给大家感受下 ...
- 比Minikube更快,使用Kind快速创建K8S学习环境
简述 K8S 如火如荼的发展着,越来越多人想学习和了解 K8S,但是由于 K8S 的入门曲线较高很多人望而却步. 然而随着 K8S 生态的蓬勃发展,社区也呈现了越来越多的部署方案,光针对生产可用的环境 ...
- 解决Centos7下中文显示乱码
第一步:先查看是不是ctr的问题: SecureCRT的修改,选项→会话选项,将外观中的字符编码集修改为UTF-8即可,其他终端程序同理 如果不是则再参照如下文档操作:https://www.cnbl ...
- java重试
项目中有很多需要重试的场景,而每次都得写如下的逻辑 for (int i=0;i++;i<retry){ try{ do(//逻辑代码); if(success){ break; } }catc ...
- css实现div多边框_box-shadow模拟多边框、outline描边实现
在css3中我们知道可以使用box-shadow属性轻松的为元素添加阴影效果,并且可以设置多组效果,每组参数值用逗号隔开.如果把box-shadow特性的两个偏移量 h-shadow .v-shado ...
- 「疫期集训day9」七月
我们暂时被击退了,可恶的德国佬----我们集结了英国人,意大利人,荷兰人,澳大利亚人,来自世界各地,我们万众一心,还能失守亚眠?----亚眠中坚守的协约国士兵 日常考爆,T1貌似全场就我傻乎乎的推式子 ...
- Django---进阶7
目录 图书管理的图书增删改查 choices参数(数据库字段设计常见) MTV与MVC模型 多对多三种创建方式 Ajax 小例子 作业 图书管理的图书增删改查 from django.shortcut ...
- Js 利用正则 在字符串中提取数字、替换非数字字符为指定字符串
var s ="总金额4500元"; var num= s.replace(/[^-]/ig,""); alert(num);// 上述示例会把数字匹配到直接转 ...
- ELKF-分布式日志收集分析平台搭建 最小化 配置过程 - 查看收集日志(windows10下搭建)
前言 Elasticsearch是与名为Logstash的数据收集和日志解析引擎以及名为Kibana的分析和可视化平台一起开发的.这三个产品被设计成一个集成解决方案,称为“Elastic Stack” ...