问题
I want to call request.getContextPath()
inside a JSP tag which extends SimpleTagSupport
, is there any way to do it?
回答1:
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();
来源:https://stackoverflow.com/questions/2098796/how-to-access-request-in-jsptags