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 get the servlet context path in Spring?
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 get the servlet context path in Spring?
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;
}