Brodie
Brodie

Reputation: 605

How to access request in JspTags?

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

Upvotes: 17

Views: 9093

Answers (1)

BalusC
BalusC

Reputation: 1108722

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();  

Upvotes: 22

Related Questions