The web app root - poc
This is under webapps folder of tomcat.
under poc folder, I have WEB-INF. Under WEB-INF, I have jsp, classes, lib folders. tiles-defs.xml (As tiles are also used) and web.xml are in WEB-INF. Under jsp folder, tiles\mainLayout contains the jsp for the actual layout. It defines the header, body and footer as below:
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jstl/xml" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<title> Tiles </title>
<body>
<div id="layoutWrapper">
<%--Header starts here --%>
<tiles:insertAttribute name="header"/>
<%--Rigth Content starts here --%>
<tiles:insertAttribute name="body"/>
<%--Footer starts here --%>
<tiles:insertAttribute name="footer"/>
</div>
</body>
</html>
Now, the jsps for the header, body and footer are in another folder - under the jsp folder i.e tiles\otherLayout. The footer jsp which contains the code for reading stock.xml is present here. This folder also contains stock.xml. Thus the code in footer.jsp is:
<div id="footerContentDiv">
<c:import url="stocks.xml" var="xmldoc"/>
<x:parse xml="${xmldoc}" var="output"/>
<p>
<table border="2" width="50%">
<tr>
<th>Stock Symbol</th>
<th>Company Name</th>
<th>Price</th>
</tr>
<x:forEach select="$output/portfolio/stock" var="item">
<tr>
<td><x:out select="symbol"/></td>
<td><x:out select="name"/></td>
<td><x:out select="price"/></td>
</tr>
</x:forEach>
</table>
<br/>
</div>
Hope this information is helpful. Please let me know if you need any other info.
I tried another approach without using tiles. Pure JSP, JSTL and this time, the c:import and x:parse xml worked and it was able to read the xml file (jsp containing the jstl code and xml document were in the same folder).
Thanks.