Issue
I'm trying to make servlet, that parses the xml and print information from it.
Here is the part my code:
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
List<Inventory> list = null;
DOMParser domParser = new DOMParser();
pw = res.getWriter();
try {
list = domParser.parse(getServletContext().getResourceAsStream("../SportInventory.xml"));
} catch (ParserConfigurationException | SAXException e) {
return;
}
pw.println("<HTML><HEAD><TITLE>title</TITLE></HEAD><BODY>");
pw.println("<p>done</p>");
pw.println("</BODY></HTML>");
pw.close();
}
Here is directories structure: https://imgur.com/4bmwdMC
schemaLocation in my xml:
xsi:schemaLocation="http://nure.ua/sportInventory sportInventory.xsd"
As a result I have next: https://imgur.com/sCzSxFc
Previously thx for helping and sorry for my bad English.
Solution
Try this:
list = domParser.parse(getServletContext().getResourceAsStream("/SportInventory.xml"))
File location must start with "/".
Answered By - lukasz.kiszka