Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Session 如何在SimpleTagSupport的doTag中访问会话_Session_Servlets - Fatal编程技术网

Session 如何在SimpleTagSupport的doTag中访问会话

Session 如何在SimpleTagSupport的doTag中访问会话,session,servlets,Session,Servlets,我有以下简单的代码: public class MyTag extends SimpleTagSupport { public MyTag() { } public void doTag() throws IOException { //needs to access the session here. how? } } 我需要访问doTag()中的会话,以便在会话中注入值。我通过getJspContext()检查了SimpleTagSuppor

我有以下简单的代码:

public class MyTag extends SimpleTagSupport {
    public MyTag() {
    }
    public void doTag() throws IOException {
        //needs to access the session here. how?
    }
}
我需要访问doTag()中的会话,以便在会话中注入值。我通过getJspContext()检查了SimpleTagSupport的所有get方法和所有get方法。奇怪的是,我找不到访问会话的方法


我错过了什么吗?

找到了答案。应该是:

getJspContext().setAttribute("attribute", "value", PageContext.SESSION_SCOPE);
希望这对其他人有帮助