如何在JspTags中访问请求?

2022-09-03 01:39:42

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


答案 1

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

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

答案 2