The ServletContext class is important in web application, often times, you need this class get the information of current deployed servlet container. Here’s a trick to show you how to get ServletContext in JSF2, via FacesContext. ServletContext servletContext = (ServletContext) FacesContext .getCurrentInstance().getExternalContext().getContext(); References ServletContext JavaDoc FacesContext JavaDoc

Read more How to get ServletContext in JSF 2

Many servlet’s developers are confuse about the different between “ServletConfig” and “ServletContext”. Actually the “ServletContext” name is quite confusing, it should change to “AppConfig” or “AppContext” in the future release 🙂 ContextConfig 1) This is one per “web application”, access globally by all the servlets’ class 2) web.xml – within the web-app element and outside […]

Read more Different between ServleConfig and ServletContext

Here’s a serlvet code example to demonstrate how to pass a parameter to whole web application by using ServletContext “init-param” in web.xml. In the deployment descriptor (web.xml) Put your parameter value in “init-param” and make sure outside the “servlet” element <servlet> <servlet-name>ServletName</servlet-name> <servlet-class>com.mkyong.ServletDemo</servlet-class> </servlet> <context-param> <param-name>email</param-name> <param-value>[email protected]</param-value> </context-param> Servlet code public void doGet(HttpServletRequest request, HttpServletResponse […]

Read more How to pass parameters to whole web application – ServletContext