Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding a context-param programmatically?

Tags:

servlets

jsf

Is there a way to add a context-param programmatically? I don't want to add in the web-xml. Specifically I want to do what the answer in this post suggests: Invoking methods with parameters by EL in JSF 1.2.

like image 429
Toby Samples Avatar asked Mar 01 '26 20:03

Toby Samples


1 Answers

Yes it is possible.

In the servlet's init method, use

getServletConfig().getServletContext().setInitParameter("[Parameter name]", "[value]");

OR simply

getServletContext().setInitParameter("[Parameter name]", "[value]");

This must do the trick for you.

For the application load,

In web.xml, when you declare this servlet, provide <load-on-startpup> element as 1 for this servlet.

<servlet>
 <servlet-name>TestServlet</servlet-name>
 <servlet-class>TestServlet</servlet-class>
 <load-on-startup>1</load-on-startup>
</servlet>
like image 74
Ravindra Gullapalli Avatar answered Mar 04 '26 15:03

Ravindra Gullapalli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!