Last Updated on 31 July 2019   |   Print Email
Sometimes we need to retrieve values of parameters which are configured in web.xmlfile from our Struts action class. For example, we define a parameter named host in the web.xml file as follows:
To read this parameter from within an action class, it requires doing the following things:
Make the action class implementing the org.apache.struts2.util.ServletContextAware interface.
Implement the setServletContext() method to obtain reference of the ServletContext object which is passed by Struts (for any action class that implements the ServletContextAware interface).
In action method, we can read value of any parameter defined in the web.xmllike this:
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.
Comments