博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springboot 配置jsp支持
阅读量:6875 次
发布时间:2019-06-26

本文共 3965 字,大约阅读时间需要 13 分钟。

springboot默认并不支持jsp模板,所以需要配置。

下面是一个可以运行的例子:

首先配置属性文件:

spring.http.encoding.force=truespring.http.encoding.charset=UTF-8spring.http.encoding.enabled=trueserver.tomcat.uri-encoding=UTF-8server.port=8080spring.mvc.view.prefix: /WEB-INF/jsp/spring.mvc.view.suffix: .jspapplication.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;@SpringBootApplicationpublic 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;@Controllerpublic class WelcomeController {    @Value("${application.message}")    private String message;        @GetMapping("/welcome")    public String welcome(Map
model) { model.put("time", new Date().getTime()); model.put("message", this.message); return "welcome"; } @GetMapping("/test") public String test(){ return "test"; }}

 

pom.xml 文件的所有配置:

4.0.0
spring-boot-sample-web-jsp
ming
0.0.1-SNAPSHOT
war
Spring Boot Web JSP Sample
Spring Boot Web JSP Sample
http://projects.spring.io/spring-boot/
Pivotal Software, Inc.
http://www.spring.io
${basedir}/../..
/
1.5.4.RELEASE
org.springframework.boot
spring-boot-starter-web
${springboot.version}
javax.servlet
jstl
1.2
org.springframework.boot
spring-boot-starter-tomcat
${springboot.version}
provided
org.apache.tomcat.embed
tomcat-embed-jasper
8.5.6
provided
org.springframework.boot
spring-boot-starter-test
${springboot.version}
test
org.springframework.boot
spring-boot-maven-plugin
org.apache.maven.plugins
maven-surefire-plugin
false

 

例子下载:

 

转载地址:http://cbpfl.baihongyu.com/

你可能感兴趣的文章
解决oracle_4031错误的方法
查看>>
C# Out,Ref 学习总结
查看>>
CentOS 7.4如何安装Python3
查看>>
instanceof
查看>>
activity的四种模式
查看>>
z-index
查看>>
git 和github
查看>>
Vue的路由
查看>>
RESTful API
查看>>
mysql之select(二)
查看>>
万能分页存储过程
查看>>
jQuery模板插件jsrender
查看>>
内部类概述
查看>>
linux ln 命令使用参数详解(ln -s 软链接)
查看>>
结队开发项目—NABC模型
查看>>
qt5.4解决输出中文乱码问题
查看>>
深入分析Java ClassLoader原理
查看>>
Vim编辑器
查看>>
Codevs 3304 水果姐逛水果街Ⅰ 线段树
查看>>
linux共享windows资料
查看>>