Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getServletConfig().getServletContext() equivalent 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?

like image 471
Freakyuser Avatar asked Jan 22 '13 13:01

Freakyuser


People also ask

What is ServletContext in Spring?

It's used to wire the configurations from Spring beans together and use them for the application. Use ApplicationContext if you want to retrieve the information of Spring beans. Use ServletContext if you want to get/set attribute those shared to all Servlet.

What is the difference between ServletConfig and ServletContext interface?

ServletConfig is used for sharing init parameters specific to a servlet while ServletContext is for sharing init parameters within any Servlet within a web application.


1 Answers

for SpringMVC

@Autowired ServletContext servletContext; 
like image 96
Evgeniy Fitsner Avatar answered Sep 23 '22 05:09

Evgeniy Fitsner