【转载】spring-boot 项目跳转到JSP页面
原路径:https://blog.csdn.net/qq_36820717/article/details/80008225
1、新建spring-boot项目 目录结构如下

2、新建TestController.java文件,内容如下
package com.example.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class TestController {
@RequestMapping("/index")
public String index(){
return "index";
}
}
3、新建webapp文件夹,与resources同级。

4、新建JSP页面,此时发现New里面没有JSP页面。需要设置一下才会出现哟。

5、点击File->Project Structure...

6、点击Modules->绿色加号->Web

7、双击此处

8、选择刚刚新建的webapp,点击OK,继续OK。

9、此时webapp上有个蓝色圆点表示设置成功。

10、在webapp上单击右键New,此时出现JSP文件。

11、新建index.jsp

12、index.jsp内容
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1 style="color: red">Hello World</h1>
</body>
</html>
13、新建MyWebAppConfigurer类

14、MyWebAppConfigurer内容
package com.example.controller;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
@Configuration
public class MyWebAppConfigurer extends WebMvcConfigurerAdapter {
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/");
viewResolver.setSuffix(".jsp");
viewResolver.setViewClass(JstlView.class);
return viewResolver;
}
}
15、在pom.xml中加入依赖JAR包
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>7.0.59</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
16、启动Application,访问127.0.0.1:8080/index

17、跳转完成。
以上就是spring-boot跳转JSP页面的过程,下面说说跳转遇到的坑。
一、缺少依赖JAR包
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
跳转失败

提示还算明确,缺少jstl标签
二、使用provided版本JSP解析器JAR包,
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
下载JSP文件

改为
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>7.0.59</version>
</dependency>
问题解决,至于为什么provided版本的不行,感兴趣的小伙伴可以深究下,留言给我。
综上所述,两个依赖JAR包一个都不能少。
---------------------
作者:黄粱大梦
来源:CSDN
原文:https://blog.csdn.net/qq_36820717/article/details/80008225
【转载】spring-boot 项目跳转到JSP页面的更多相关文章
- Spring Boot项目跳转不到jsp页面是怎么回事
SpringBoot访问不了JSP但却能进入后台 一直报错: 解决方法: 改成下面的
- Eclipse使用Debug模式调试Spring Boot项目时跳转到exitCurrentThread的问题
Spring Boot项目使用了spring-boot-devtools工具且在Eclipse中Debug调试会自动跳转到这个方法: public static void exitCurrentThr ...
- Spring Boot (二)集成Jsp与生产环境部署
一.简介 提起Java不得不说的一个开发场景就是Web开发,也是Java最热门的开发场景之一,说到Web开发绕不开的一个技术就是JSP,因为目前市面上仍有很多的公司在使用JSP,所以本文就来介绍一下S ...
- spring boot学习01【搭建环境、创建第一个spring boot项目】
1.给eclipse安装spring boot插件 Eclipse中安装Spring工具套件(STS): Help -> Eclipse Marketplace... 在Search标签或者Po ...
- Spring Boot-初学01 -使用Spring Initializer快速创建Spring Boot项目 -@RestController+spEL -实现简单SpringBoot的Web页面
1.IDEA:使用 Spring Initializer快速创建项目 IDE都支持使用Spring的项目创建向导快速创建一个Spring Boot项目: 选择我们需要的模块:向导会联网创建Spring ...
- [转]VsCode搭建Java开发环境(Spring Boot项目创建、运行、调试)
源码地址:https://github.com/YANGKANG01/Spring-Boot-Demo 安装扩展 安装如下两个主要扩展即可,这两个扩展已关联java项目开发主要使用的maven.spr ...
- spring boot项目如何测试,如何部署
有很多网友会时不时的问我,spring boot项目如何测试,如何部署,在生产中有什么好的部署方案吗?这篇文章就来介绍一下spring boot 如何开发.调试.打包到最后的投产上线. 开发阶段 单元 ...
- 一个很有趣的示例Spring Boot项目,使用Giraphe CMS和Spring Boot
6: 这是一个很有趣的示例Spring Boot项目,使用Giraphe CMS和Spring Boot. Giraphe是基于Spring Boot的CMS框架. https://github.co ...
- 创建一个 Spring Boot 项目,你会几种方法?
我最早是 2016 年底开始写 Spring Boot 相关的博客,当时使用的版本还是 1.4.x ,文章发表在 CSDN 上,阅读量最大的一篇有 42W+,如下图: 2017 年由于种种原因,就没有 ...
随机推荐
- Django Views Decorator
Django的试图函数的装饰器主要有: HTTP请求方法 条件视图处理 GZip压缩 改变页眉 缓存 官网文档 HTTP请求方法 该装饰器是设置允许访问HTTP协议的方法,装饰器在django.vie ...
- 11、E-commerce in Your Inbox:Product Recommendations at Scale-----产品推荐(prod2vec和user2vec)
一.摘要 本文提出一种方法,将神经语言模型应用在用户购买时间序列上,将产品嵌入到低维向量空间中.结果,具有相似上下文(即,其周围购买)的产品被映射到嵌入空间中附近的向量. 二.模型: 低维项目向量表示 ...
- 字体样式(.ttf/.woff)文件的配置引入
在引入前端框架部分功能时,有时需要配置字体样式.可以这样配置:在 .ttf的同级目录下,创建icon.css文件,写入: @font-face {font-family: "element- ...
- UVALive-8072 Keeping On Track 树形dp 联通块之间缺失边的个数
题目链接:https://cn.vjudge.net/problem/UVALive-8072 题意 给出n+1个点和n条边,每对点之间只能存在一条边. 现在要找出一个节点,使得去掉这个点后,所剩每对 ...
- 2019-03-18 Python time 将2015年11月20日转换为2015-11-20
#ReportingDate = soup.select('body > div.main > div > div.ctr > div.recruit > ul > ...
- MVC总结
一.转自https://zhuanlan.zhihu.com/p/35680070 MVC无人不知,可很多程序员对MVC的概念的理解似乎有误,换言之他们一直在错用MVC,尽管即使如此软件也能被写出来, ...
- 【hihocoder 1519】 逃离迷宫II
[题目链接]:http://hihocoder.com/problemset/problem/1519?sid=1098756 [题意] Chinese [题解] bfs题; 根据bfs的性质; 第一 ...
- angular-resource
上一篇中讲到使用$http同服务器进行通信,但是功能上比较简单,angularjs还提供了另外一个可选的服务$resource,使用它可以非常方便的同支持restful的服务单进行数据交互. 安装 n ...
- COGS——T 2739. 凯伦和咖啡
http://www.cogs.pro/cogs/problem/problem.php?pid=2739 ★★☆ 输入文件:coffee.in 输出文件:coffee.out 简单对比时 ...
- struct和typedef
struct Test { int i; }; 解析:此处声明一个Test的结构体. 使用:在C语言中:struct Test t(此处的struct不可省略),在C++中:Test t(能够省略st ...