1

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

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Evan Knowles
  • 7,426
  • 2
  • 37
  • 71

1 Answers1

1

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555