Reputation: 2814
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?
Upvotes: 28
Views: 35998
Reputation: 7253
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;
}
Upvotes: 8
Reputation: 8836
A solution is posted here: ServletContext and Spring MVC
@Autowired
ServletContext context;
Upvotes: 4