【问题标题】:request.contextPath not resolved inside Apache Tiles JSP fragmentsrequest.contextPath 未在 Apache Tiles JSP 片段中解析
【发布时间】:2016-06-22 23:55:11
【问题描述】:

我有一个 Spring + Apache Tiles 3 应用程序。

我有一个布局,里面有页眉、正文和页脚:

defaultLayout.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>

<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title><tiles:getAsString name="title" /></title>
    <link href="<c:url value='/static/css/bootstrap.css' />"  rel="stylesheet"></link>
    <link href="<c:url value='/static/css/app.css' />" rel="stylesheet"></link>
</head>

<body>
        <header id="header">
            Web Application Context Path="${pageContext.request.contextPath}"
            <tiles:insertAttribute name="header" />
        </header>

        <section id="sidemenu">
            <tiles:insertAttribute name="menu" />
        </section>

        <section id="site-content">
            <tiles:insertAttribute name="body" />
        </section>

        <footer id="footer">
            <tiles:insertAttribute name="footer" />
        </footer>
</body>
</html>

“${pageContext.request.contextPath}”在布局中可以正常工作,但在 JSP 子级中却不行:

menu.jsp

<nav>
<a href="${pageContext.request.contextPath}/"><img class="logo" src="${pageContext.request.contextPath}/static/img/Linux-icon.png"></a>
<ul id="menu">
    <li><a href="${pageContext.request.contextPath}/">Home</a></li>
   <li><a href="${pageContext.request.contextPath}/products">Products</a></li>
   <li><a href="${pageContext.request.contextPath}/contactus">Contact Us</a></li>
</ul>

这会在结果 HTML 中“按原样”打印“${pageContext.request.contextPath}”。

【问题讨论】:

    标签: spring maven servlets


    【解决方案1】:

    尝试使用&lt;%@ page isELIgnored="false" %&gt;。它会解决你的问题

    【讨论】:

      【解决方案2】:

      既然您提到了 HTML 代码并说上下文路径是“按原样”打印的,那么这段代码是否在 HTML 文件中?然后就不行了。

      检查这个问题 - ${pageContext.request.contextPath} is not working on plain HTML

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-30
      • 1970-01-01
      • 2019-08-14
      • 2020-09-24
      • 1970-01-01
      • 2018-08-15
      相关资源
      最近更新 更多