Freemarcker獲取專案根目錄

2021-08-27 16:42:12 字數 633 閱讀 8013

現在知道了freemarker模板技術,發現在用freemarker之後引入到檔案中的css和js檔案都沒有起作用,在jsp頁面中還可以用">來設定絕對路徑,請問怎麼樣在ftl檔案中設定標籤的值?還有,生成靜態頁面之後怎麼樣顯示使用者登陸了的資訊?

全部採用絕對定位即可,比如我的使用,在乙個全域性macro定義中定義變數basepath即可

<#-- 取得 應用的絕對根路徑 -->

預祝成功

如果是在中還需要這個絕對路徑那應該怎麼辦呢?我現在的想法是,在省城html的action中直接用httpservletrequest獲取到絕對路徑path,放到root中,然後在ftl頁面中使用

<#-- 取得 應用的絕對根路徑 -->

<#assign basepath=request.contextpath>

<#macro head>

預祝成功

所以在其他ftl檔案中可以使用他了,比如在home.ftl中:

獲取專案所在路徑

取到 http localhost 8080 myproject string basepath request.getscheme request.getservername request.getserverport request.getcontextpath string relativel...

獲取專案執行位址

web專案中經常需要獲取專案執行時請求的url,例如需要重定向頁面時,方法如下 request.getscheme 當前鏈結使用的協議 request.getservername 伺服器位址 request.getserverport 埠號 request.getcontextpath 應用名稱 r...

thymeleaf 獲取專案路徑

p th text p a th href a 效果圖如下 插入一段本地不需要加上專案名稱,在正式環境下伺服器下需要加上專案名稱的判斷,免得本地和伺服器上都改來改去,有時候忘記改了,就gg了 a class item th each taopiao,u th if ne 8080 th href f...