Reputation: 12621
I have set an environment variable in windows by name "sample". Can I get this environment variable's value using below code?
System.getProperty("sample");
in UAT environment I have LINUX OS. Can I set the same environment variable in LINUX OS and retrieve the same using System.getProperty("sample")
?
I mean does System.getProperty("sample");
retrieves irrespective of the operating system?
Also, I would like to get the environment variable's value in JSP.I know it is not recommended to keep logic in jsp but still, I need to use it. Can I use System.getProperty("sample");
in jsp? Please help me.
Upvotes: 0
Views: 11488
Reputation: 360046
Use System.getenv()
to retrieve environment variables, not System.getProperty()
. The latter is for (as the name implies) system properties.
What's the difference? Java system properties and environment variables
If you need to access an environment variable in a JSP, you're doing something wrong. At the very least, use a servlet. More reading: How to avoid Java code in JSP files?
Upvotes: 16