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>

例子下载:http://pan.baidu.com/s/1pKNDJD5

springboot 配置jsp支持的更多相关文章

  1. Springboot(二)springboot之jsp支持

    参考恒宇少年的博客:https://www.jianshu.com/p/90a84c814d0c springboot内部对jsp的支持并不是特别理想,而springboot推荐的视图是Thymele ...

  2. 搭建SpringBoot、Jsp支持学习笔记

    Spring Boot 添加JSP支持 大体步骤: (1)            创建Maven web project: (2)            在pom.xml文件添加依赖: (3)     ...

  3. Jetty:配置JSP支持

    选择JSP实现 从Jetty-9.2開始,使用Apache Jasper作为默认JSP容器实现.在前面的版本号中使用的是Glassfish Jasper,在后面的版本号中也能够继续使用它. Jetty ...

  4. springboot配置jsp

    spring.mvc.view.prefix= /WEB-INF/jsp/ spring.mvc.view.suffix= .jsp pom.xml <!--jsp支持--> <!- ...

  5. springboot 添加 jsp支持

    idea 新建springboot项目 packageing:选择 war next   勾选web 添加jar包 <dependency> <groupId>org.apac ...

  6. 十.spring-boot添加jsp支持

    1.创建maven web project: 2.在添加web依赖 3.配置application.properties支持jsp 4.添加一个controller类 5.加入jsp页面 6.启动类 ...

  7. spring-boot 配置jsp

    sring-boot 集成  jsp spring-boot默认使用的页面展示并不是jsp,若想要在项目中使用jsp还需要配置一番. 虽然spring-boot中也默认配置了InternalResou ...

  8. springboot整合jsp,完成公交车站路线图

    转: springboot整合jsp,完成公交车站路线图 点赞再看,养成习惯 开发环境: jdk 8 intellij idea tomcat 8 mysql 5.7 maven 3.6 所用技术: ...

  9. springboot配置对jsp页面的解析支持

    pom.xml文件配置依赖信息 <!--引入Spring Boot内嵌的Tomcat对JSP的解析包,不加解析不了jsp页面--> <dependency> <group ...

随机推荐

  1. css3动画的原理 及 各种效果制作

    1. 制作小球弹动效果 在这篇文章中,我们将会去探究一下浏览器是如何去处理CSS Animations和CSS Transitions的,   c 以便使你在写一些动画效果之前就可以对该动画在浏览器中 ...

  2. C# 解决datatable写入文件内存溢出问题

    1.程序生成目标平台设为x64 2.文件写入后主动回收内存

  3. 如何从MTK机器的NVRAM中获取WIFI mac地址

    在MTK的机器中,如果不用特定的工具烧写MAC地址,在开机后打开WIFI后会显示: "NVRAM WARNING: Err=0x10" 这就是没有烧写mac地址的原因,所以每次打开 ...

  4. 如何在未越狱的ios系统安装ipa文件

    首先我们先下载一个PP助手正版在电脑上 用iphone打开http://z.25pp.com/?from=bdpz,根据网页上的教程,我们安装好PP助手正版(注意是正版!!) 将手机连接电脑,在电脑上 ...

  5. I.MX6 CAAM

    /********************************************************************************* * I.MX6 CAAM * 说明 ...

  6. Linux之screen命令详解

    一.nohup 工作中经常会遇到这样的需求,通过SecureCRT或其它工具远程到服务器执行某个任务,而这个任务耗时又比较长,你又不得不等待它执行完毕,但是如果此间如果关掉窗口或断开连接又会导致任务被 ...

  7. 6-3 Add Two Polynomials(20 分)

    Write a function to add two polynomials. Do not destroy the input. Use a linked list implementation ...

  8. C#方法(函数)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. time函数及其用法

    Linux下三种时间 st_atime:文件中的数据最后被访问的时间           Time when file data was last accessed. Changed by  the  ...

  10. c# 设置自动隐藏任务栏、获取状态

    from: http://stackoverflow.com/questions/1381821/how-to-toggle-switch-windows-taskbar-from-show-to-a ...