I've got a jsp page that writes the xml code for a sitemap and displays it on the jsp page which works fine. I've been trying to make it so the jsp file automatically writes to the xml file (siteMap.xml) completely rewriting the xml file each time. Unfortunately, I haven't been able to do this. A .jfp stores the sitemap in an arraylist then the jsp prints it out on using iterator. Anyone have any ideas or help? Here's the code:

<%@ page language="java" contentType="text/html;charset=UTF-8"
%><%@ page import="internet.portletImpl.siteMap.SiteMapContro ller"
%><%@ page import="java.io.*;"
%><%@ taglib uri="netui-tags-databinding.tld" prefix="netui-data"
%><%@ taglib uri="netui-tags-html.tld" prefix="netui"
%><%@ taglib uri="netui-tags-template.tld" prefix="netui-template"
%><%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"
%><%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"
%><%response.setContentType("text/xml");
%><%out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");%>
<%out.write("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">");%>
<logic:iterate name="siteMapXML" id="map">
<%out.write("<url>");%>
<%out.write("<loc>");%><bean:write name="map" property="me.href" filter="false"/><%out.write("</loc>");%>
<%out.write("</url>");%>
<logic:notEmpty name="map" property="children">
<logic:iterate name="map" id="level2" property="children">
<%out.write("<url>");%>
<%out.write("<loc>"); %><bean:write name="level2" property="me.href" filter="false"/><% out.write("</loc>");%>
<%out.write("</url>");%>
<logic:notEmpty name="level2" property="children">
<logic:iterate name="level2" id="level3" property="children">
<%out.write("<url>");%>
<%out.write("<loc>");%><bean:write name="level3" property="me.href" filter="false"/><%out.write("</loc>");%>
<%out.write("</url>");%>
<logic:notEmpty name="level3" property="children">
<logic:iterate name="level3" id="level4" property="children">
<%out.write("<url>");%>
<%out.write("<loc>"); %><bean:write name="level4" property="me.href" filter="false"/><% out.write("</loc>");%>
<%out.write("</url>");%>
<logic:notEmpty name="level3" property="children">
<logic:iterate name="level3" id="level4" property="children">
<%out.write("<url>");%>
<%out.write("<loc>");%><bean:write name="level4" property="me.href" filter="false"/><%out.write("</loc>");%>
<%out.write("</url>");%>
</logic:iterate>
</logic:notEmpty>
</logic:iterate>
</logic:notEmpty>
</logic:iterate>
</logic:notEmpty>
</logic:iterate>
</logic:notEmpty>
</logic:iterate>
<%out.write("</urlset>");%>