SpringBoot: 7.整合jsp(转)
springboot内部对jsp的支持并不是特别理想,而springboot推荐的视图是Thymeleaf,对于java开发人员来说还是大多数人员喜欢使用jsp
1、创建maven项目,添加pom依赖

<!--springboot项目依赖的父项目-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent> <dependencies>
<!--注入springboot启动器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <!-- jstl标签库 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- jasper,tomcat对jsp的监听 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
</dependencies>

2、创建springboot的全局配置文件application.porerties
#视图层位置前缀
spring.mvc.view.prefix=/WEB-INF/jsp/
#视图层后缀
spring.mvc.view.suffix=.jsp
3、创建controller

package com.bjsxt.controller; import com.bjsxt.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import java.util.ArrayList;
import java.util.List; /**
* Created by Administrator on 2019/2/6.
*/
@Controller
public class UserController { @RequestMapping("/toUserList")
public String toUserList(Model model){
List<User> userList=new ArrayList<User>();
userList.add(new User(1L,"张三","男"));
userList.add(new User(2L,"李四","女"));
userList.add(new User(3L,"王五","男"));
model.addAttribute("userList",userList);
return "user_list";
}
}

4、创建jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>用户列表</title>
</head>
<body> <table border="1px solid red">
<tr>
<th>id</th>
<th>姓名</th>
<th>性别</th>
</tr>
<c:forEach items="${userList}" var="user">
<tr>
<td>${user.id}</td>
<td>${user.name}</td>
<td>${user.sex}</td>
</tr>
</c:forEach>
</table>
</body>
</html>

5、创建启动类

package com.bjsxt; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; /**
* Created by Administrator on 2019/2/6.
*/
@SpringBootApplication
public class App { public static void main(String[] args){
SpringApplication.run(App.class,args);
}
}

项目目录结构
SpringBoot: 7.整合jsp(转)的更多相关文章
- SpringBoot整合Jsp和Thymeleaf (附工程)
前言 本篇文章主要讲述SpringBoot整合Jsp以及SpringBoot整合Thymeleaf,实现一个简单的用户增删改查示例工程.事先说明,有三个项目,两个是单独整合的,一个是将它们整合在一起的 ...
- SpringBoot 同时整合thymeleaf html、vue html和jsp
问题描述 SpringBoot如何同时访问html和jsp SpringBoot访问html页面可以,访问jsp页面报错 SpringBoot如何同时整合thymeleaf html.vue html ...
- 03-01:springboot 整合jsp
1.修改pom文件,添加坐标 <!-- jstl --> <dependency> <groupId>javax.servlet ...
- springboot整合jsp踩坑
springboot以其高效的开发效率越来越多的用在中小项目的开发,并且在分布式开发中的使用也很广泛,springboot官方推荐的前端框架却是thymeleaf,并且默认不支持jsp,而大部分jav ...
- springboot整合jsp模板
springboot整合jsp模板 在使用springboot框架里使用jsp的时候,页面模板使用jsp在pom.xnl中需要引入相关的依赖,否则在controller中无法返回到指定页面 〇.搭建s ...
- SpringBoot第十二篇:整合jsp
作者:追梦1819 原文:https://www.cnblogs.com/yanfei1819/p/10953600.html 版权声明:本文为博主原创文章,转载请附上博文链接! 引言 Sprin ...
- springboot学习入门简易版五---springboot2.0整合jsp(11)
springboot对jsp支持不友好,内部tomcat对jsp不支持,需要使用外部tomcat,且必须打包为war包. 1 创建maven项目 注意:必须为war类型,否则找不到页面. 且不要把js ...
- SpringBoot整合jsp技术
1.修改pom.xml文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&qu ...
- Idea中SpringBoot整合JSP
最近在学习SpringBoot,看到SpringBoot整合jsp,顺带记录一下. 1.创建一个SpringBoot项目 点击Next 注意:packaging选中War,点击Next Webà选中W ...
- 【SpringBoot】08.SpringBoot整合jsp
SpringBoot整合jsp 1.修改pom文件加入两个坐标jstl标签库和jasper <project xmlns="http://maven.apache.org/POM/4. ...
随机推荐
- golang embedded structs
golang 中把struct 转成json格式输出 package main import ( "encoding/json" "fmt" ) type Pe ...
- Solving Docker permission denied while trying to connect to the Docker daemon socket
The error message tells you that your current user can’t access the docker engine, because you’re la ...
- Java 正则表达式获取两个字符中间的内容
利用 正则表达式 获取两个字符串中间的值 直接上代码吧,不是很难. public static void main(String[] args) { // 内容 String value = &quo ...
- JS 中获取服务器时间的注意点
在通过js获取服务器时间时,遇到了小小的问题,但造成的影响挺大的,所以写出来提醒大家,在获取服务器时间时一定要细心要多测试多验证. js 中使用以下方法获取服务器时间时要注意两点: 1.xhr.ope ...
- HGOI 20191108 题解
Problem A 新婚快乐 一条路,被$n$个红绿灯划分成$n+1$段,从前到后一次给出每一段的长度$l_i$,每走$1$的长度需要$1$分钟. 一开始所有红绿灯都是绿色的,$g$分钟后所有红绿灯变 ...
- DataTable转List,DataTable转为Model对象帮助类
DataTable转List,DataTable转为Model对象帮助类 public class ModelConvertHelper<T> where T : new() { publ ...
- Java虚拟机与平台无关性
概述 代码编译的结果从本地机器码转变为字节码,是存储格式发展的一小步,却是编程语言发展的一大步. --<深入理解Java虚拟机>(从这里可以看到,字节码是一种文件格式) 我们都知道计算机只 ...
- 利用简易爬虫完成一道基础CTF题
利用简易爬虫完成一道基础CTF题 声明:本文主要写给新手,侧重于表现使用爬虫爬取页面并提交数据的大致过程,所以没有对一些东西解释的很详细,比如表单,post,get方法,感兴趣的可以私信或评论给我.如 ...
- Ubuntu使用PBIS认证
1:下载 https://github.com/BeyondTrust/pbis-open/releases wget https://github.com/BeyondTrust/pbis-open ...
- git status: HEAD detached from origin/master问题的解决
问题:执行git status,提示: HEAD detached from origin/master 原因:分支选错了,后续的提交都提交到了一个匿名分支之上,整个状态是游离了的 解决方法: 1.查 ...