Life cycle:
- created when webapp boots
- destroyed when webapp closed
ServletContext servletContext = this.getServletContext(); //ServletContext servletContext servletContext = this.getServletConfig().getServletContext(); servletContext.setAttribute("ABC", new Object()); //(String, Object)
Init Parameter
<context-param> <param-name>Country</param-name> <param-value>China</param-value> </context-param>
request.getServletContext().getInitParameter("Country");
Get Resource
Properties pp = new Properties(); InputStream fis = getServletContext().getResourceAsStream("WEB-INF/settings.properties"); pp.load(fis); getServletContext().getRealPath("WEB-INF/settings.properties");
No comments:
Post a Comment