在jsp页面可以可以application取得,我现在code中,想直接取得当前请求的ServletContext咋做??

解决方案 »

  1.   


     Servlet中// 获取ServletContextServletContext context = getServletContext();// 获取String userName = (String)context.getAttribute("USERNAME"); 在对应的Jsp中String userName = (String)application.getAttribute("USERNAME");
      

  2.   

    谢谢回复!!
    你这压迫配置Servlet,好像Filter,Listenner也可以吧
    但是我不想配置任何东西!直接在取得 ,就像.net下的HttpContext.Current;取得一样的!
      

  3.   

    jsp源码可供参考:
      private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();
    ...  
    pageContext = _jspxFactory.getPageContext(this, request, response,
           null, true, 8192, true);
          _jspx_page_context = pageContext;
          application = pageContext.getServletContext();
    ...
      

  4.   

    谢谢 我刚才去看了 Servlet生成的源代码!
      

  5.   

    ServletActionContext.getServletContext()
    这个?