We help IT Professionals succeed at work.

How to define/retrieve an application specific parameter in an J2EE application

jaxox
jaxox asked
on
Medium Priority
562 Views
Last Modified: 2013-11-24
I would like to define a application specific variable.  When the application start up, I can load it into some context variable.  Then, some java bean can access these context and do something with the defined variable.  Is there any way to do it?
Comment
Watch Question

student
CERTIFIED EXPERT
Commented:
>define a application specific variable.  
You could define one in your web app's web.xml ;
<context-param>
                          <param-name>name</param-name>
                          <param-value>jaxox</param-value>
</context-param>  
On a JSP, you could access with
String name = application.getInitParameter("name");
>Then, some java bean can access these context and do something with the defined variable  
(I think you are talking about a javabean here,not a EJB. Please confirm.)
That will take some more work. Please read jim's solution and my assisted solution at  
http://www.experts-exchange.com/Programming/Languages/Java/J2EE/JSP/Q_21811332.html   
Top Expert 2004

Commented:
You can edit your server startup script and in the line when you start the server you can add -D params. -Dkey="Value". Inside your webapp or services or Jsp's you can get the parameter by System.getProperty("key")

Explore More ContentExplore courses, solutions, and other research materials related to this topic.