spring項目獲取ServletContext


(1)生命周期

  ServletContext中的屬性的生命周期從創建開始,到服務器關閉而

(2).獲取ServletContext

  1、request獲取servletContext

    ServletContext servletContext = request.getServletContext();

  2、使用ContextLoader

    ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();

  3、使用spring注入自動注入

    @Autowired

    private ServletContext servletContext;

(3).使用ServletContext存取

  1、添加屬性:setAttribute(String name,Object ob);

  2、得到值:   getAttribute(String);    //返回Object

  3、刪除屬性:removeAttribute(String name);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM