1、SpringBoot整合之SpringBoot整合JSP
SpringBoot整合JSP
一、创建SpringBoot项目,仅选择Web模块即可




二、在POM文件中添加依赖
<!-- 添加servlet依赖模块 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<!-- 添加jstl标签库依赖模块 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!--添加tomcat依赖模块.-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<!-- 使用jsp引擎,springboot内置tomcat没有此依赖 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
三、创建目录:webapp/WEB-INF、webapp/jsps
注意:一定要在main目录下,与 /java 同级

四、修改步骤三中的目录结构

五、在核心配置文件中添加视图解析器的前缀和后缀
文件位置:src/main/resources/application.properties
spring.mvc.view.prefix=/jsps/ //设定视图解析器的前缀,这里的前缀根据你jsp文件的位置进行选择
spring.mvc.view.suffix=.jsp //设定视图解析器的后缀
六、创建JSP

文件位置:webapp/jsps/test.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>Hello, test.jsp</h1><br/>
1+1=${1+1}<br/>
${requestScope.time}<br/>
</body>
</html>
七、创建一个action进行测试

package cn.byuan.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
@Controller
@RequestMapping("/test")
public class JavaServicePagesTest {
private static final String datePattern="yyyy-MM-dd E HH:mm:ss";
@RequestMapping("/m1.action")
public String methodOne(HttpServletRequest request){
request.setAttribute("time", new SimpleDateFormat(datePattern).format(new Date()));
return "test";
}
}
八、配置web resources directorys

九、运行项目,打开浏览器输入URL
http://localhost:8080/text/m1.action

源码地址:https://github.com/byuan98/springboot-integration/tree/master/test001_springboot_jsp
1、SpringBoot整合之SpringBoot整合JSP的更多相关文章
- SpringBoot第九集:整合JSP和模板引擎Freemarker/Thymeleaf(2020最新最易懂)
SpringBoot第九集:整合JSP和模板引擎(2020最新最易懂) 当客户通过前端页面提交请求后,我们以前是怎么做的?后端接收请求数据,处理请求,把响应结果交给模板引擎JSP,最后将渲染后的JSP ...
- (九) SpringBoot起飞之路-整合/集成Swagger 2 And 3
兴趣的朋友可以去了解一下其他几篇,你的赞就是对我最大的支持,感谢大家! (一) SpringBoot起飞之路-HelloWorld (二) SpringBoot起飞之路-入门原理分析 (三) Spri ...
- springboot+jpa+mysql+swagger整合
Springboot+jpa+MySQL+swagger整合 创建一个springboot web项目 <dependencies> <dependency> < ...
- java框架之SpringBoot(12)-消息及整合RabbitMQ
前言 概述 大多数应用中,可通过消息服务中间件来提升系统异步通信.扩展解耦的能力. 消息服务中两个重要概念:消息代理(message broker)和目的地(destination).当消息发送者发送 ...
- java框架之SpringBoot(13)-检索及整合Elasticsearch
ElasticSearch介绍 简介 我们的应用经常需要使用检索功能,开源的 Elasticsearch 是目前全文搜索引擎的首选.它可以快速的存储.搜索和分析海量数据.SpringBoot 通过整合 ...
- Springboot 2.0.4 整合Mybatis出现异常Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
在使用Springboot 2.0.4 整合Mybatis的时候出现异常Property 'sqlSessionFactory' or 'sqlSessionTemplate' are require ...
- SpringBoot Druid整合,SpringBoot 集成Druid
SpringBoot Druid整合,SpringBoot 集成Druid ================================ ©Copyright 蕃薯耀 2018年4月8日 http ...
- SpringBoot+SpringMVC+MyBatis快速整合搭建
作为开发人员,大家都知道,SpringBoot是基于Spring4.0设计的,不仅继承了Spring框架原有的优秀特性,而且还通过简化配置来进一步简化了Spring应用的整个搭建和开发过程.另外Spr ...
- SpringBoot:4.SpringBoot整合Mybatis实现数据库访问
在公司项目开发中,使用Mybatis居多.在 SpringBoot:3.SpringBoot使用Spring-data-jpa实现数据库访问 中,这种jpa风格的把sql语句和java代码放到一起,总 ...
- SpringBoot与PageHelper的整合示例详解
SpringBoot与PageHelper的整合示例详解 1.PageHelper简介 PageHelper官网地址: https://pagehelper.github.io/ 摘要: com.gi ...
随机推荐
- 29.Map,可变参数
1.Map集合 1.1Map集合概述和特点[理解] 单列集合一次存一个元素 双列集合一次存两个元素 键:不能重复的 值:可以重复的 Map集合概述 interface Map<K, ...
- MSSQL·将一对多的数据合并为以指定分隔符的数据
阅文时长 | 0.05分钟 字数统计 | 142.4字符 主要内容 | 1.引言&背景 2.Stuff函数语法&模拟场景 3.声明与参考资料 『MSSQL·将一对多的数据合并为以指定分 ...
- Powershell阻止确认
要阻止弹出确认提示,需要设置-Confirm为false, new-VM -Name $hostname -Template $template -VMHost 10.11.31.5 -OSCusto ...
- [bug] C:warning: implicit declaration of function ‘getline’
参考 https://blog.csdn.net/loushuai/article/details/38983793
- [刷题] 350 Intersection of Two Arrays
要求 给定两个数组nums,求两个数组交集 输出结果与元素在两个数组中出现的次数一致 不考虑输出结果的顺序 举例 nums1=[1,2,2,1] nums2=[2,2] 结果:[2,2] 思路 使用m ...
- linux下获取占用CPU资源最多的10个进程,可以使用如下命令组合:
linux下获取占用CPU资源最多的10个进程,可以使用如下命令组合: ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head linux下获取占用 ...
- Cron 任务入门指南
Cron 是您可以在任何类 Unix 操作系统中找到的最有用的实用程序之一.它用于安排命令在特定时间执行.这些预定的命令或任务被称为 "Cron 任务".Cron 通常用于运行计划 ...
- C++知识点案例 笔记-3
1.基类指针等与派生类的兼容 2.构造函数 3.析构函数 4.虚基类 5.虚函数 6.虚析构函数 ==基类指针等与派生类的兼容== #include <iostream> #include ...
- shell应用之监测电脑内存、负载和磁盘的使用情况
1 #!/bin/bash 2 for i in $(cat ip.txt);do 3 #内存 4 total_memo=$(ssh $i "free -m" |grep Mem ...
- JQuery Ajax 请求参数 List 集合处理
引言 JQuery Ajax 发送请求参数一般都是基本类型,比如 String.int:那么,请求参数如果是 List 集合应该如何处理呢? 情况一:Aajx 发送 List 类型请求参数 举例如下: ...