Access the value of welcome-file-list in web.xml

233 views Asked by At

Is there any way of accessing the welcome-file-list element in the web.xml without having to re-parse the web.xml itself?

1

There are 1 answers

0
BalusC On BEST ANSWER

No. There's no public JSF or Servlet API for that.

Best what you can do is to grab JAXP+XPath.

InputStream input = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/WEB-INF/web.xml");
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(input);
XPathExpression xpath = XPathFactory.newInstance().newXPath().compile("web-app/welcome-file-list/welcome-file");
NodeList nodes = (NodeList) xpath.evaluate(document, XPathConstants.NODESET);

for (int i = 0; i < nodes.getLength(); i++) {
    String welcomeFile = nodes.item(i).getFirstChild().getNodeValue().trim();
    // ...
}

If you happen to use JSF utility library OmniFaces, you can use its WebXml utility class.

List<String> welcomeFiles = WebXml.INSTANCE.getWelcomeFiles();

See also: