SpringBoot14 之JSP
来源:互联网 发布:wwwtaoyitu淘宝号查询 编辑:程序博客网 时间:2024/06/05 05:52
1、加入依赖,
注意:
provided这个标签在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下的某一个包里面,否则启动时候进程关闭,启动失败。
@SpringBootApplicationpublic class APP { public static void main(String[] args){ SpringApplication.run(APP.class); }}
3、创建一个Controller
@Controllerpublic 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>
0 0
- SpringBoot14 之JSP
- SpringBoot14-springboot核心-外部配置,日志配置,Profile配置
- JSP验证之JSP页面
- JSP学习之jsp指令
- JSP之JSP运行过程
- JSP之jsp内置标签
- jsp学习之jsp指令
- JavaWeb之JSP--------------JSP小结
- jsp 之 入门 jsp注释
- JSP学习之----JSP声明/JSP输出表达式/JSP脚本
- jsp template之我见
- jsp template之我见
- JSP之路起航
- 资源共享之Jsp基础
- jsp安全之我见
- JSP之page指令
- JSP之常见错误
- JSP之out对象
- Ubuntu不输入密码执行sudo命令方法介绍
- maven 常用命令
- linux 知识
- Java简述 Java Stream(流)的分类, 四大基本流的介绍
- PHP mysql_real_escape_string() 函数
- SpringBoot14 之JSP
- WebStorm2016破解方法
- 正则表达式大全
- javascript深入了解匿名函数和闭包
- linux常用命令——2.文件搜索命令
- 关于传递多个参数时使用构建器demo
- shell 知识点备忘
- 测试用例模板和例子
- 蓝桥杯——趣味数组问题二(2017.2.14)