Question

I am writing a JSP page with custom tags. Normally the page would be like:

<h1>Welcome <%request.getRemoteUser()%> <h1>

I want to introduce custom tags for this instead of having to write script lets. So I decided to write one tag handler. The problem is I do not know a way to get request object in tag handler.

My tag handler looks like:

UserNameTagHandler extends TagSupport{
    public int doTag() throws JspException {
        String userName = request.getRemoteUser();    //How can I get the correct request object.
    }
}
Was it helpful?

Solution

Extend TagSupport and then use pageContext variable.

HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top