请求jsp $ {pageContext.request.contextPath} dosent [英] jsp ${pageContext.request.contextPath} dosent get requested

查看:128
本文介绍了请求jsp $ {pageContext.request.contextPath} dosent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有一个.jsp项目,我的欢迎页面是一个servlet

Currently i have a .jsp project where my welcome page is a servlet

<welcome-file>frontpage</welcome-file>

servlet集获取两个资源,一个包含< nav>和包含<的页脚页脚>

The servlet sets gets two ressources, a header file containing the < nav> and a footer containing the < footer>

request.setAttribute("header1", sc.getResource("/includes/nav.jsp").toString());
request.setAttribute("footer", sc.getResource("/includes/footer.jsp").toString());

转发到index.jsp页面

And forwards to the index.jsp page

getServletContext().getRequestDispatcher("/WEB-INF/jsp/index.jsp").forward(request, response);

我的问题是。
当我得到ressource(footer.jsp)时,我怎么能在footer.jsp中动态导入/包含图像?

My question is. When i get the ressource (footer.jsp), how can i in the footer.jsp dynamically import / include images?

我试过以下

<img src="${pageContext.request.contextPath}/images/picture1.png" alt="picture1"/>

但表达式$ {pageContext.request.contextPath}被视为字符串而不是命令,并且没有得到上下文路径。

But the expression ${pageContext.request.contextPath} gets treated as a string instead of a command, and does not get the context path.

我怀疑它是因为footer.jsp的内容是以这种方式获取的,并且它们的上下文路径实际上是在footer.jsp。

I suspect its because the content of the footer.jsp is fetched in this manner and their for the context path isint actually ever requested within the footer.jsp.

但我该怎样解决这个问题?

But how do i solve this?

推荐答案

添加<%@ page isELIgnored =false%> 在JSP页面的顶部,以启用表达式语言。

add <%@ page isELIgnored="false" %> in top of your JSP page, to enable expression language.

并包含一个其他用途的JSP页面< jsp:include ,如:

and to include a JSP page with other use <jsp:include like:

<jsp:include page="/includes/nav.jsp"/>
<jsp:include page="/includes/footer.jsp"/>

这篇关于请求jsp $ {pageContext.request.contextPath} dosent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆