springboot 配置jsp支持
springboot默认并不支持jsp模板,所以需要配置。
下面是一个可以运行的例子:
首先配置属性文件:

spring.http.encoding.force=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
server.tomcat.uri-encoding=UTF-8 server.port=8080 spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
application.message: Hello world

然后配置启动类:

package sample.jsp; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer; @SpringBootApplication
public class Application extends SpringBootServletInitializer { @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
} public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
} }

最后写一下控制层:

package sample.jsp; import java.util.Date;
import java.util.Map; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
public class WelcomeController { @Value("${application.message}")
private String message; @GetMapping("/welcome")
public String welcome(Map<String, Object> model) {
model.put("time", new Date().getTime());
model.put("message", this.message);
return "welcome";
} @GetMapping("/test")
public String test(){
return "test";
} }

pom.xml 文件的所有配置:

<?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>
<groupId>spring-boot-sample-web-jsp</groupId>
<artifactId>ming</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Spring Boot Web JSP Sample</name>
<description>Spring Boot Web JSP Sample</description>
<url>http://projects.spring.io/spring-boot/</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
<m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
<springboot.version>1.5.4.RELEASE</springboot.version>
</properties>
<dependencies>
<!-- Compile -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${springboot.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Provided -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>${springboot.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>8.5.6</version>
<scope>provided</scope>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${springboot.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
</project>

springboot 配置jsp支持的更多相关文章
- Springboot(二)springboot之jsp支持
参考恒宇少年的博客:https://www.jianshu.com/p/90a84c814d0c springboot内部对jsp的支持并不是特别理想,而springboot推荐的视图是Thymele ...
- 搭建SpringBoot、Jsp支持学习笔记
Spring Boot 添加JSP支持 大体步骤: (1) 创建Maven web project: (2) 在pom.xml文件添加依赖: (3) ...
- Jetty:配置JSP支持
选择JSP实现 从Jetty-9.2開始,使用Apache Jasper作为默认JSP容器实现.在前面的版本号中使用的是Glassfish Jasper,在后面的版本号中也能够继续使用它. Jetty ...
- springboot配置jsp
spring.mvc.view.prefix= /WEB-INF/jsp/ spring.mvc.view.suffix= .jsp pom.xml <!--jsp支持--> <!- ...
- springboot 添加 jsp支持
idea 新建springboot项目 packageing:选择 war next 勾选web 添加jar包 <dependency> <groupId>org.apac ...
- 十.spring-boot添加jsp支持
1.创建maven web project: 2.在添加web依赖 3.配置application.properties支持jsp 4.添加一个controller类 5.加入jsp页面 6.启动类 ...
- spring-boot 配置jsp
sring-boot 集成 jsp spring-boot默认使用的页面展示并不是jsp,若想要在项目中使用jsp还需要配置一番. 虽然spring-boot中也默认配置了InternalResou ...
- springboot整合jsp,完成公交车站路线图
转: springboot整合jsp,完成公交车站路线图 点赞再看,养成习惯 开发环境: jdk 8 intellij idea tomcat 8 mysql 5.7 maven 3.6 所用技术: ...
- springboot配置对jsp页面的解析支持
pom.xml文件配置依赖信息 <!--引入Spring Boot内嵌的Tomcat对JSP的解析包,不加解析不了jsp页面--> <dependency> <group ...
随机推荐
- jsp如何判断mysql数据库中是否已经存在添加的某条记录的方法
String query="select * from hdxcy_info where XcyName='"+XcyName+"'"; String sqlS ...
- 如何在IDEA启动多个Spring Boot工程实例
在我讲解的案例中,经常一个工程启动多个实例,分别占用不同的端口,有很多读者百思不得其解,在博客上留言,给我发邮件,加我微信询问.所以有必要在博客上记录下,方便读者. step 1 在IDEA上点击Ap ...
- 阿里云windows时间同步服务地址
偶然发现的, 记录一下 ntp1.aliyun.com
- 一个Self Taught Learning的简单例子
idea: Concretely, for each example in the the labeled training dataset xl, we forward propagate the ...
- Java第五次作业--面向对象高级特性(抽象类和接口)
一.学习要点 认真看书并查阅相关资料,掌握以下内容: 掌握抽象类的设计 掌握接口的设计 理解简单工厂设计模式 理解抽象类和接口的区别 掌握包装类的应用 掌握对象的比较方法和比较器的使用 学习使用日期操 ...
- 响应: 500 OOPS: priv_sock_get_int 错误: 读取目录列表失败
/************************************************************************* * 响应: 500 OOPS: priv_sock ...
- 算法初探:Tensorflow及PAI平台的使用
前言 Tensorflow这个词由来已久,但是对它的理解一直就停留在“听过”的层面.之前做过一个无线图片适配问题智能识别的项目,基于Tensorflow实现了GoogLeNet - Inception ...
- 1106-冒泡算法C程序(语法树)
#include <stdio.h> main() { int i,j,temp; int a[10]; for(i=0;i<10;i++) scanf ("%d,&quo ...
- 自定义redis session
1.思路 2.程序实现 1.用户系统类 这里模拟一个蹩脚的用户系统类(userSystem),如下: #coding=utf-8 #Redis实现用户系统 __author__ = 'beginman ...
- C#多线程应用:子线程更新主窗体控件的值(一)
我记得以前写过一次关于多线程的调用及更新的文章,由于时间比较久了,现在一时没找到.在做项目的时候,用到了多线程,还是有很多的同事在问多线程更新主窗体的事情,现在就这个事情做个记录. 说起多线程之间的更 ...