从servlet访问JSP会话
我试图从我的servlet建立和访问会话,但我无法让它工作 所有教程只需调用request.getSession(true);对于会话对象,但我得到“请求无法解决” 我只需要使用taglibs,jsp页面中没有逻辑 如何访问会话数据? 谢谢从servlet访问JSP会话,jsp,taglib,Jsp,Taglib,我试图从我的servlet建立和访问会话,但我无法让它工作 所有教程只需调用request.getSession(true);对于会话对象,但我得到“请求无法解决” 我只需要使用taglibs,jsp页面中没有逻辑 如何访问会话数据? 谢谢 从taglib访问会话数据的正确示例是: package controller; import java.io.*; import javax.servlet.*; import javax.servlet.jsp.*; import javax.serv
从taglib访问会话数据的正确示例是:
package controller;
import java.io.*;
import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.http.*;
import javax.servlet.jsp.tagext.*;
public class Initialize extends BodyTagSupport
{
public int doEndTag() throws JspTagException
{
try
{
// Implementation
JspWriter out = pageContext.getOut();
HttpSession session = pageContext.getSession(true);
out.println(session.getId());
return SKIP_BODY;
}
catch(IOException error)
{
throw new JspTagException(error);
}
}
}
好的,我知道了。我必须使用HttpSession session=pageContext.getSession();page指令应该包含session=“true”。page指令不需要session=“true”指令,因为这是默认行为。除非您明确指定session=“false”,否则每个jsp页面都将为您创建一个会话。
package controller;
import java.io.*;
import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.http.*;
import javax.servlet.jsp.tagext.*;
public class Initialize extends BodyTagSupport
{
public int doEndTag() throws JspTagException
{
try
{
// Implementation
JspWriter out = pageContext.getOut();
HttpSession session = pageContext.getSession(true);
out.println(session.getId());
return SKIP_BODY;
}
catch(IOException error)
{
throw new JspTagException(error);
}
}
}