springBoot(6):web开发-模板引擎jsp
一、新建工程
注意新建的工程下没有webapp目录eclipse下会自动创建webapp目录这里我们需要自动创建一个webapp目录并创建WEB-INF。
对ServletInitializer.java进行说明
1、这个类相当于我们以前的web.xml
2、只有3.0以上才可以否则需要添加web.xml
二、配置
2.1、pom.xml配置
1
2
3
4
5
6
7
8
9
|
< dependency >
< groupId >org.apache.tomcat.embed</ groupId >
< artifactId >tomcat-embed-jasper</ artifactId >
< scope >provided</ scope >
</ dependency >
< dependency >
< groupId >javax.servlet</ groupId >
< artifactId >jstl</ artifactId >
</ dependency >
|
2.2、配置前缀与后缀类似于sspringmvc
1
2
3
4
|
spring.profiles.active=dev #配置前缀与后缀 spring.mvc.view.prefix=/WEB-INF/templates/ spring.mvc.view.suffix=.jsp |
四、代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
package com.example.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
/** * Created by ly on 2017/6/16.
*/
@Controller @RequestMapping ( "/demo1" )
public class Index {
@RequestMapping ( "/index" )
public String index(Model model) throws Exception {
model.addAttribute( "title" , "ceshi" );
return "index" ;
}
} |
idea这里有点问题下面改用eclipse结构如下
index.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <!DOCTYPE html> < html >
< head lang = "en" >
< title >Spring Boot Demo - FreeMarker</ title >
< link href = "/static/css/index.css" rel = "stylesheet" />
</ head >
< body >
< h1 id = "title" >${title}</ h1 >
< c:url value = "http://www.roncoo.com" var = "url" />
< spring:url value = "http://www.roncoo.com" htmlEscape = "true" var = "springUrl" />
Spring URL: ${springUrl}
< br >
JSTL URL: ${url}
<!-- <script type="text/javascript" src="/static/webjars/jquery/2.1.4/jquery.min.js"></script>
<script>
$(function(){
$('#title').click(function(){
alert('1o');
});
})
</script> -->
</ body >
</ html >
|
访问http://localhost:8988/demo1/index
本文转自我爱大金子博客51CTO博客,原文链接http://blog.51cto.com/1754966750/1939115如需转载请自行联系原作者
我爱大金子
springBoot(6):web开发-模板引擎jsp的更多相关文章
- SpringBoot(四) Web开发 --- Thymeleaf、JSP
Spring Boot提供了spring-boot-starter-web为Web开发予以支持,spring-boot-starter-web为我们提供了嵌入的Tomcat以及Spring MVC的依 ...
- SpringBoot:Web开发
西部开源-秦疆老师:基于SpringBoot 2.1.6 的博客教程 , 基于atguigu 1.5.x 视频优化 秦老师交流Q群号: 664386224 未授权禁止转载!编辑不易 , 转发请注明出处 ...
- SpringBoot之WEB开发-专题二
SpringBoot之WEB开发-专题二 三.Web开发 3.1.静态资源访问 在我们开发Web应用的时候,需要引用大量的js.css.图片等静态资源. 默认配置 Spring Boot默认提供静态资 ...
- springboot用于web开发
1.使用SpringBoot:1)创建SpringBoot应用,选中我们需要的模块:2)SpringBoot已经默认将这些场景配置好了,只需要在配置文件中指定少量配置就可以运行起来3)自己编写业务代码 ...
- SpringBoot学习(七)-->SpringBoot在web开发中的配置
SpringBoot在web开发中的配置 Web开发的自动配置类:在Maven Dependencies-->spring-boot-1.5.2.RELEASE.jar-->org.spr ...
- springboot java web开发工程师效率
基础好工具 idea iterm2 和 oh-my-zsh git 热加载 java web项目每次重启时间成本太大. 编程有一个过程很重要, 就是试验, 在一次次试验中探索, 积累素材优化调整程序模 ...
- SpringBoot系列:Spring Boot使用模板引擎JSP
一.Java模板引擎 模板引擎(这里特指用于Web开发的模板引擎)是为了使用户界面与业务数据(内容)分离而产生的,它可以生成特定格式的文档,用于网站的模板引擎就会生成一个标准的HTML文档. 在jav ...
- SpringBoot(四) -- SpringBoot与Web开发
一.发开前准备 1.创建一个SpringBoot应用,引入我们需要的模块 2.SpringBoot已经默认将这些场景配置好了,只需要在配置文件中指定少量配置,就能运行起来 3.编写业务代码 二.静态资 ...
- Spring Boot整合模板引擎jsp
jsp也算是一种模板引擎吧.整合jsp前,先说一下运行SpringBoot项目的几种方式 1. 运行SpringBoot项目的几种方式 1.1 使用内嵌Tomcat运行项目 在IDE中右键运行启动类, ...
随机推荐
- Servlet 中文乱码问题解析及详细解决方法
使用 servlet 向客户端浏览器回送中文时,经常出现中文乱码的问题,这里给大家完完全全地搞明白: 一.基本常识 中文系统默认是 GBK 编码(GBK是对GB2312的补充,包含它) 需要处理编码问 ...
- Windows下Python3.6.2+Django-1.11.5+httpd-2.4.27-win64-VC14部署网站
最近项目组正在上python+django.现在将部署过程总结下,相关文件也备份下,面得每次都要弄半天.网上很多不靠谱的做法,让我反复试错,浪费不少时间. 原材料: Python3.6.2 httpd ...
- java web之Filter详解
java web之Filter详解 2012-10-20 0 个评论 作者:chenshufei2 收藏 我要投稿 .概念: Filter也称之为过滤器,它是Servlet技术中比较激动人心的技术,W ...
- 简单完成Excel导出
Excel的导出只需要三步即可完成: 1,完成excel的工具类编写,直接复制即可 package cn.com.bcl.util; import java.util.List; import org ...
- ${param.pageNo}是什么意思?
1.${param.id}与request.getParameter("id"):功能相同2.param.id获取输入的参数id,也可理解为的是form或者div表单里的ID. r ...
- 《SQL 反模式》 学习笔记
第一章 引言 GoF 所著的的<设计模式>,在软件领域引入了"设计模式"(design pattern)的概念. 而后,Andrew Koenig 在 1995 年造了 ...
- 第一章:shell脚本初入门
1.shell脚本中的source或者.空格再加上文件,表示加载文件中的命令及语句(困惑多时终于解开^-^) 2.脚本开头书写好作者版本等信息,方便维护:流程语句提前把格式写好,防止遗漏 3.定义字符 ...
- Jbox弹窗控件无法获取子页面元素值得问题
top.$.jBox.open("iframe:${ctx}/report/reportSubjectDatabase/toChildWindow", "请选择重构快照表 ...
- L22 Data Augmentation数据增强
数据 img2083 链接:https://pan.baidu.com/s/1LIrSH51bUgS-TcgGuCcniw 提取码:m4vq 数据cifar102021 链接:https://pan. ...
- Daily Scrum 1/4/2015
Process: After New year's Day, we start our project in plan. Zhanyang: Add some useful UI in the IOS ...