How to access the session within doTag of SimpleTagSupport

Refresh

April 2019

Views

306 time

1

I have the following simple code:

public class MyTag extends SimpleTagSupport {
    public MyTag() {
    }
    public void doTag() throws IOException {
        //needs to access the session here. how?
    }
}

I need to access the session within doTag() to inject a value in the session. I checked all get methods of SimpleTagSupport and all get methods through getJspContext(). Strangely, I am unable to find a way to access the session.

Did I miss anything?

1 answers

1

Found out the answer. It should be:

getJspContext().setAttribute("attribute", "value", PageContext.SESSION_SCOPE);

Hope this helps someone else.