How can I access environment variables from a JSP page? Does one of the implicit objects give access to them? I couldn't find an example addressing this specific issue. Ideally I'm looking for something like:
<c:set var="where" value="${myEnvironment.machineName}">
You can read the properties file at the server start-up using ServletContextListener and store it as application scoped attribute to access it from anywhere in the application.
Steps to follow:
.properties:
web.xml:
AppServletContextListener.java:
JSP:
Then you can just treat it as Map in EL.
or
Read more about JSTL Core
c:set
TagThe
<c:set>
tag is JSTL-friendly version of thesetProperty
action. The tag is helpful because it evaluates an expression and uses the results to set a value of aJavaBean
or ajava.util.Map
object.The
<c:set>
tag has following attributes:If target is specified, property must also be specified.
Read more about it HERE
If you are looking for sample code then find it here. Please find it at below posts. It might help you.
Acces value between two jsp with jstl
JSP - Standard Tag Library (JSTL) Tutorial
More samples on other scopes.
In your case you have set an attribute
where
in defaultpage
scope.