使用EL或scriptlet代码在jsp自定义标记文件中的getRealPath()

时间:2010-11-08 11:50:25

标签: jsp jsp-tags

我正试图从像这样的标记文件中访问servlet路径;

<%@tag description="put the tag description here" pageEncoding="UTF-8"%>
<%=pageContext.getServletContext().getRealPath("/")%>

然而它抱怨它无法找到符号; string:/// xxxxx:89:找不到符号 symbol:变量pageContext location:class org.apache.jsp.tag.web.xxxx

有关如何在标记文件中访问该值的任何建议吗?

2 个答案:

答案 0 :(得分:1)

由于表达式出现在标记文件中,pageContext不是有效的隐式对象。如您所知,application有效,jspContextjavax.servlet.jsp.JspContext的实例)也是如此。在相关说明中,getRealPath可能会返回null ...

答案 1 :(得分:0)

哦,看起来app.getRealPath(“images”)就是标签上下文中的那个

相关问题