<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>betweenGo &#187; Servlet</title>
	<atom:link href="http://betweengo.com/category/java/servlet/feed/" rel="self" type="application/rss+xml" />
	<link>http://betweengo.com</link>
	<description>We make Ruby on Rails easy.  We make ATG easy.</description>
	<lastBuildDate>Tue, 06 Dec 2011 14:03:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Dynamically generate sitemap.xml</title>
		<link>http://betweengo.com/2009/03/02/dynamically-generate-sitemapxml/</link>
		<comments>http://betweengo.com/2009/03/02/dynamically-generate-sitemapxml/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 15:55:52 +0000</pubDate>
		<dc:creator>Frank Kim</dc:creator>
				<category><![CDATA[Servlet]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://betweengo.com/?p=449</guid>
		<description><![CDATA[sitemap.xml is a top level document on your website &#8220;for webmasters to inform search engines about pages on their sites that are available for crawling.&#8221;  Google not surprisingly has its own documentation on how to improve your site&#8217;s visibility using sitemap.xml. Typically sitemap.xml is a static file that is hand generated.  But on large sites [...]
Related posts:<ol>
<li><a href='http://betweengo.com/2008/12/30/servletexception-root-cause/' rel='bookmark' title='ServletException root cause'>ServletException root cause</a></li>
<li><a href='http://betweengo.com/2009/03/02/mod_rewrite-to-bypass-security/' rel='bookmark' title='mod_rewrite to bypass security'>mod_rewrite to bypass security</a></li>
<li><a href='http://betweengo.com/2006/04/04/howto-log-sql-on-jboss/' rel='bookmark' title='How to Log SQL on JBoss'>How to Log SQL on JBoss</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a title="Sitemaps XML format " href="http://www.sitemaps.org/protocol.php">sitemap.xml</a> is a top level document on your website &#8220;<a title="sitemaps.org" href="http://www.sitemaps.org/">for webmasters to inform search engines about pages on                 their sites that are available for crawling</a>.&#8221;  Google not surprisingly has its own documentation on <a title="Webmaster Tools: Improve your site's visibility in Google Search" href="https://www.google.com/webmasters/tools/docs/en/protocol.html">how to improve your site&#8217;s visibility</a> using sitemap.xml.</p>
<p>Typically sitemap.xml is a static file that is hand generated.  But on large sites it makes more sense to generate this dynamically.  One way to do this is to generate it on demand using a servlet.  Here is my simple solution.  I did not include the implementation for outputPages() since that will be specific to each application server&#8217;s DB hierarchy or web server&#8217;s file structure.</p>
<pre>public class SiteMap extends HttpServlet {

  protected static final String MIME_TYPE_XML = "application/xml";

  // XML tags
  protected static final String SITE_MAP_XML_INFO = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;";
  protected static final String SITE_MAP_BEGIN =
      "&lt;urlset\n\txmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n\txsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\n\t\thttp://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\"&gt;";
  protected static final String SITE_MAP_END = "&lt;/urlset&gt;";

  protected static final String LOC_BEGIN = " &lt;loc&gt;";
  protected static final String LOC_END = "&lt;/loc&gt;";
  protected static final String PRIORITY_BEGIN = " &lt;priority&gt;";
  protected static final String PRIORITY_END = "&lt;/priority&gt;";
  protected static final String URL_BEGIN = "&lt;url&gt;";
  protected static final String URL_END = "&lt;/url&gt;";

  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

    // set content type to be XML
    response.setContentType(MIME_TYPE_XML);

    // get writer
    PrintWriter out = response.getWriter();

    // output header
    out.println(SITE_MAP_XML_INFO);
    out.println(SITE_MAP_BEGIN);

    // output pages
    outputPages(request, out);

    // output end
    out.println(SITE_MAP_END);
    out.close();
  }

  protected void outputPage(String uri, String priority, PrintWriter out, String urlStart) {
    out.println(URL_BEGIN);
    out.println(LOC_BEGIN + urlStart + uri + LOC_END);
    out.println(PRIORITY_BEGIN + priority + PRIORITY_END);
    out.println(URL_END);
  }
}</pre>
<p>Then you configure web.xml to use the SiteMap servlet.</p>
<pre>&lt;servlet&gt;
    &lt;servlet-name&gt;sitemap&lt;/servlet-name&gt;
    &lt;servlet-class&gt;com.upromise.olm.app.servlet.SiteMap&lt;/servlet-class&gt;
&lt;/servlet&gt;

&lt;servlet-mapping&gt;
    &lt;servlet-name&gt;sitemap&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/sitemap.xml&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;</pre>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbetweengo.com%2F2009%2F03%2F02%2Fdynamically-generate-sitemapxml%2F&amp;title=Dynamically%20generate%20sitemap.xml" id="wpa2a_2"><img src="http://betweengo.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>Related posts:<ol>
<li><a href='http://betweengo.com/2008/12/30/servletexception-root-cause/' rel='bookmark' title='ServletException root cause'>ServletException root cause</a></li>
<li><a href='http://betweengo.com/2009/03/02/mod_rewrite-to-bypass-security/' rel='bookmark' title='mod_rewrite to bypass security'>mod_rewrite to bypass security</a></li>
<li><a href='http://betweengo.com/2006/04/04/howto-log-sql-on-jboss/' rel='bookmark' title='How to Log SQL on JBoss'>How to Log SQL on JBoss</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://betweengo.com/2009/03/02/dynamically-generate-sitemapxml/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
