如何在JspTags中访问请求?

时间:2010-01-20 03:06:16

标签: java jsp jsp-tags

我想在扩展request.getContextPath()的JSP标记内调用SimpleTagSupport,有什么方法可以做到吗?

1 个答案:

答案 0 :(得分:20)

首先通过继承的PageContext获取SimpleTagSupport#getJspContext(),然后通过HttpServletRequest获取PageContext#getRequest()

PageContext pageContext = (PageContext) getJspContext();  
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();