getServletConfig().getServletContext() equivalent in Spring

后端 未结 3 928
余生分开走
余生分开走 2020-12-29 04:42

I referred to a lot of posts but still I am unable to find a correct working answer.
I want to get it from my Java class itself and not using EL in jsp.

How to

3条回答
  •  醉梦人生
    2020-12-29 05:13

    Another way is implementing ServletConfigAware in the class that depends on ServletContext. In the setServletConfig method you'll get an instance of ServletContext and you can do there what you have to do.

    public class MyClass implements ServletConfigAware {
    
        private ServletConfig config;
    
        public void setServletConfig(ServletConfig servletConfig) {
            this.config = servletConfig;
        }
    

提交回复
热议问题