Java获取Http对象的方法

获取Session:

HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
HttpSession session = request.getSession();
Object obj = session.getAttribute("name");

 

获取Application:

public class XXXX implements ServletContextAware {
  private ServletContext application;
  public void setServletContext(ServletContext servletContext){
    this.application = servletContext;
  }
  public void main(){
    Object obj = application.getAttribute("name");
  }
}

 

你可能感兴趣的:(java)