【Thymeleaf】获取绝对路径
前言
- thymeleaf 3.0
获取绝对路径
使用Thymeleaf模板引擎想要拼出绝对路径
<a th:href="${#request.getScheme() + '://' + #request.getServerName() + ':' + #request.getServerPort() + @{/login}} ">点我啊!</a>
等效的写法:
<a th:href="${#httpServletRequest.getScheme() + '://' + #httpServletRequest.getServerName() + ':' + #httpServletRequest.getServerPort() + @{/login}} ">点我啊!</a>
解释下:
Inside a web environment there is also direct access to the following objects (note these are objects, not maps/namespaces):
#request : direct access to the javax.servlet.http.HttpServletRequest object associated with the current request.
按照官方文档的说法,内置变量 #request
等同于 javax.servlet.http.HttpServletRequest
。
因此,可以按照 javax.servlet.http.HttpServletRequest
拼接URL的方式,拼接绝对路径。
javax.servlet.http.HttpServletRequest
的方法说明
getScheme()
获取协议getServerName()
获取服务器名getServerPort()
服务器端口getContextPath()
APP根路径
勘误
之前给出的写法有些问题,已修正。
下面是之前给出的错误的写法:
<a th:href="${#httpServletRequest.getScheme() + '://' + #httpServletRequest.getServerName() + ':' + #request.getServerPort() + #request.getContextPath() + @{/login}} ">点我啊!</a>
参考
https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#appendix-a-expression-basic-objects
【Thymeleaf】获取绝对路径相关推荐
- thymeleaf 获取yml中的值_Thymeleaf模板引擎学习
开发传统Java WEB项目时,我们可以使用JSP页面模板语言,但是在SpringBoot中已经不推荐使用JSP页面进行页面渲染了.从而Thymeleaf提供了一个用于整合Spring MVC的可选模 ...
- thymeleaf获取url地址跳转时所带参数
获得http://localhost:8081/goods_detail.htm?type=0&goodsId=2的 参数 function getParam(){//通过substring方 ...
- 获取服务器路径的方式 【记录】
JSP页面获取服务器路径的方式 1.basePath方式 <% String path = request.getContextPath(); String basePath = request ...
- php获取服务器文件路径,php获取服务器路径
php获取服务器路径 内容精选 换一换 为加强对系统数据的容灾管理,云堡垒机支持配置日志备份,提高审计数据安全性和系统可扩展性.本小节主要介绍如何在系统配置FTP/SFTP服务器参数,将日志远程备份至 ...
- java 获取绝对路径
原文地址:http://hi.baidu.com/%C3%E7%D0%A4/blog/item/9e887b6c2e7005ef4216946c.html 1.利用System.getProperty ...
- linux c 获取绝对路径各种方法分析
昨天肚腩群里有人问LINUX下C如何获取程序绝对路径.初看这问题,肚腩觉得很简单啊,就用getcwd或者argv[0]就可以了.写了个程序试试, #include <unistd.h>in ...
- 通过 SHGetSpecialFolderLocation、SHGetPathFromIDList 函数获取常用路径
本例效果图: 代码文件: unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Contr ...
- java取路径含中文_java获取项目路径中文乱码
以下内容转自:http://blog.csdn.net/dream_broken/article/details/31762807# 项目的文件名称推荐都是英文名称,但是有时不可避免使用了中文,获取项 ...
- request获取各种路径 转,记下来免得 以后忘记了。
2019独角兽企业重金招聘Python工程师标准>>> 转:http://zjutsoft.iteye.com/blog/1084260 从request获取各种路径总结 reque ...
最新文章
- canvas用2d渲染出3d的感觉
- python相关linux_Python实现获取Linux系统基本信息
- Java中final、finally和finalize的区别(转)
- markdown-Macdown
- LuoguP1113 杂务
- Android UI 事件研究
- 今年的移动Pwn2own破解大赛:iPhone+安卓=50万美元
- getvalue参数计数不匹配_数据人:不懂业务,分析就仅仅只是提数
- [C语言 - 13] 运算符
- VRTK HTC手柄发出射线,瞬移,选择物体 VRTK和steamVR对应版本
- springmvc源码-参数解析
- VMware vSphere7 with Tanzu 安装方案
- 中国计算机语言学,【CCL 2019】中国计算语言学大会(CCL 2019)技术评测报告以及研讨会...
- className 还能这么用,你学会了吗
- 浅谈 D-Bus、udevd 和 hald
- Vue项目搭建常用配置文件!
- SharePoint中在线编辑文档
- 实验5-2 符号函数 (10分)
- Bribe the Prisoners(2009 Round 1C C)
- 体验ANT DESIGN PRO V5--项目创建并安装umi气泡工作台