码迷,mamicode.com
首页 > 编程语言 > 详细

springboot 配置jsp支持

时间:2018-05-28 17:21:52      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:project   jstl   bsp   一个   XML   plugins   apach   frame   port   

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支持

标签:project   jstl   bsp   一个   XML   plugins   apach   frame   port   

原文地址:https://www.cnblogs.com/jpfss/p/9101062.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!