Q:

How to get current Spring profile in jsp file.

I'm developing Spring MVC application. In my application I have two profiles, test and production. Test is enable when I deploy my app to test envirionemnt, Production on production environment. 
I need to get current profile in jsp file. Is it possible ? I don't want to send additional variable to get this information because file is included to lot of others files. 
Thanks

A:

Since you are using MVC, a more straightforward approach is to autowire the environment in your controller and pass the profiles in the model.
@Autowired
private Environment environment;

@RequestMapping("/needsProfile")
public String needsProfile(Model model) {
    model.addAttribute("profiles", environment.getActiveProfiles());
    return "needsProfile";
}

And in your needsProfile.jsp:
<jsp:useBean id="profiles" type="java.lang.String[]" scope="request"/>

<%-- ... --%>

<div>First Profile:  ${profiles[0]}</div>

A:

You can use something like the following:
ServletContext sc = request.getSession().getServletContext();
WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(sc);
String[] profiles = applicationContext.getEnvironment().getActiveProfiles();

