How to access request in JspTags?

Brodie picture Brodie · Jan 20, 2010 · Viewed 8.7k times · Source

I want to call request.getContextPath() inside a JSP tag which extends SimpleTagSupport, is there any way to do it?

Answer

BalusC picture BalusC · Jan 20, 2010

First get the PageContext by the inherited SimpleTagSupport#getJspContext() and then get the HttpServletRequest by PageContext#getRequest().

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