SpringBoot14 之JSP

1、加入依赖,

注意:

<scope>provided</scope>这个标签在jstl和tomcat-embed-jasper中不要加入

否则访问的时候会出现404错误。这个标签provided表示,打包的时候不需要。

<parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>1.4.1.RELEASE</version>

</parent>

<dependencies>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

<!-- servlet 依赖. -->

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>javax.servlet-api</artifactId>

<scope>provided</scope>

</dependency>

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>jstl</artifactId>

</dependency>

<!-- tomcat 的支持.-->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-tomcat</artifactId>

</dependency>

<dependency>

<groupId>org.apache.tomcat.embed</groupId>

<artifactId>tomcat-embed-jasper</artifactId>

</dependency>

</dependencies>

1、在application.properties中加入配置

# 页面默认前缀目录

spring.mvc.view.prefix=/WEB-INF/jsp/

# 响应页面默认后缀

spring.mvc.view.suffix=.jsp

# 自定义属性,可以在Controller中读取

application.hello=Hello Angel From application

2、创建启动类,这个类必须在java下的某一个包里面,否则启动时候进程关闭,启动失败。

@SpringBootApplication

public class APP {

public static void main(String[] args){

SpringApplication.run(APP.class);

}

}

3、创建一个Controller

@Controller

public class JspController {

@Value("${application.hello:Hello Angel}")

private String hello;

@RequestMapping("/helloJsp")

public String helloJsp(Model model){

System.out.println("HelloController.helloJsp().hello="+hello);

model.addAttribute("hello",hello);

return "helloJsp";

}

}

4、在WEB-INF下创建一个目录,与application.properties的配置文件一致。

创建jsp文件

 

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

</head>

<body>

helloJsp

<hr>

${hello}

</body>

</html>

 

转载于:https://my.oschina.net/huaForever/blog/807166

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值