get parameter values from web.xml inside of a bean

E

Eqbal Z

Is there a way for me to get parameter values from web.xml file inside
of a bean?
I have parameters like the following in my web.xml file:
<context-param>
<param-name>userName</param-name>
<param-value>xxxx</param-value>
</context-param>
<context-param>
<param-name>password</param-name>
<param-value>yyyy</param-value>
</context-param>

How do I get these values inside of a bean thats used in a JSP page. I
am using WAS 4.0.5 app server (its servlet 2.2 specs). I do not want
to use sessions.
 
R

Ryan Stewart

Eqbal Z said:
Is there a way for me to get parameter values from web.xml file inside
of a bean?
I have parameters like the following in my web.xml file:
<context-param>
<param-name>userName</param-name>
<param-value>xxxx</param-value>
</context-param>
*snip*

Context parameters are accessed via a ServletContext. You have to have one
of those to get the parameters.
 
Joined
Sep 22, 2009
Messages
1
Reaction score
0
As long as your bean is running within the Faces life cycle, you can access a web.xml context parameter like this:

public ExampleBean()
{
String param = FacesContext.getCurrentInstance().getExternalContext()
.getInitParameter("context parameter name");
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top