Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting servlet config-param from bean

Status
Not open for further replies.

jemminger

Programmer
Jun 25, 2001
3,453
US
i'm sure this is simple, but i can't seem to find the answer...

i have a <config-param> node in web.xml that i want to get to from a bean. what's the best way?

thanks

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
Hi Jeff,

There is no <config-param> element in the web.xml dtd, but I'm guessing you mean <context-param>, ie :

<context-param>
<param-name>hello</param-name>
<param-value>qqq</param-value>
</context-param>


In any case, to get this value :

Code:
String hello = this.getServletConfig().getServletContext().getInitParameter("hello");

but that is really only accessible from an object that extends HttpServlet.

You could also do :

Code:
String hello = request.getSession().getServletContext().getInitParameter("hello");

where request is a HttpServletRequest object.

In effect, you will either have to :
- set these values in your servlet / JSP, and pass them to the relevant bean, or
- add them into a HttpSession object to be retrieved by the bean, or
- pass a HttpServletRequest object to the bean (bit messy).

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top