Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access environment variable from java servlet

I would like to know if there is any way I can access an environment variable from a java servlet. I know that I can pass params to the servlet using web.xml but I need to pass some value at run-time.

The requirement is something like this -

A non-web based app running at the server side sets some value (environment variable) and it has to be accessed during a web session (from the servlet). I am using apache web server.

I am new to web based programming, so forgive me if I am asking something silly/stupid.

like image 936
Happy Go Lucky Avatar asked Aug 20 '09 01:08

Happy Go Lucky


1 Answers

If you want to retrieve os environment variable use System.getenv() Method.

public static Map<String,String> getenv()

Returns an unmodifiable string map view of the current system environment. The environment is a system-dependent mapping from names to values which is passed from parent to child processes.

like image 151
KV Prajapati Avatar answered Sep 29 '22 04:09

KV Prajapati