【问题标题】:<%=request.getContextPath()%> equivalent in Thymeleaf<%=request.getContextPath()%> 等效于 Thymeleaf
【发布时间】:2018-05-13 00:21:06
【问题描述】:

我使用 Spring Initializer、嵌入式 Tomcat、Thymeleaf 模板引擎生成了一个 Spring Boot Web 应用程序,并将其打包为可执行 JAR 文件。

使用的技术:

Spring Boot 2.0.0.M6,Java 8,maven

我在application.properties 中定义了这个属性

server.servlet.context-path=iberiaWebUtils

我想知道在我的 Thymeleaf 模板中是否有与

等效的内容
<a href="/<%=request.getContextPath()%>/iberiaReport/download">

【问题讨论】:

    标签: java spring spring-boot thymeleaf


    【解决方案1】:

    您可以通过

    获得server.servlet.context-path
    ${#httpServletRequest.getContextPath()}
    

    你可以写

    <a href="@{/iberiaReport/download}">
    

    【讨论】:

    • 只是一个小修正:应该是:&lt;a th:href="@{/iberiaReport/download}"&gt;,使用th:href 而不是简单的href
    猜你喜欢
    • 2019-01-08
    • 1970-01-01
    • 1970-01-01
    • 2020-03-23
    • 2020-01-05
    • 2019-06-29
    • 2021-09-22
    • 1970-01-01
    • 2012-10-21
    相关资源
    最近更新 更多