How to access the session within doTag of SimpleTagSupport


April 2019


306 time


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


Found out the answer. It should be:

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

Hope this helps someone else.