13

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.

2
  • Maybe you want to use databases. Commented Aug 20, 2009 at 1:50
  • What if the application doesn't use a database? What if you need to get a users settings? Commented Aug 20, 2009 at 3:22

2 Answers 2

10

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.

Sign up to request clarification or add additional context in comments.

Comments

6

Use System.getenv(), available since JDK 5.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.