<?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; Java</title>
	<atom:link href="http://betweengo.com/category/java/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, 08 May 2012 19:30:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Programming Secure FTP in Java</title>
		<link>http://betweengo.com/2011/02/21/programming-secure-ftp-in-java/</link>
		<comments>http://betweengo.com/2011/02/21/programming-secure-ftp-in-java/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 16:00:00 +0000</pubDate>
		<dc:creator>Frank Kim</dc:creator>
				<category><![CDATA[Java SE]]></category>
		<category><![CDATA[jsch]]></category>
		<category><![CDATA[sftp]]></category>

		<guid isPermaLink="false">http://betweengo.com/2011/02/21/programming-secure-ftp-in-java/</guid>
		<description><![CDATA[Often server applications need to upload or download files using FTP.&#160; But in this age of increasing security awareness vendors are now asking this be done using SFTP (Secure FTP). Fortunately this is not difficult using the JSch (Java Secure Channel) library.&#160; The downloadable JSch archive includes numerous examples.&#160; I used the Sftp.java to implement [...]
Related posts:<ol>
<li><a href='http://betweengo.com/2005/08/12/acc-not-connecting/' rel='bookmark' title='ACC not connecting'>ACC not connecting</a></li>
<li><a href='http://betweengo.com/2008/09/01/java-method-with-generic-return-type/' rel='bookmark' title='Java Method with Generic Return Type'>Java Method with Generic Return Type</a></li>
<li><a href='http://betweengo.com/2008/04/18/oracle-tns-listener-service-not-starting/' rel='bookmark' title='Oracle TNS Listener service not starting'>Oracle TNS Listener service not starting</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a title="Comes with built-in FTP server | Flickr" href="http://www.flickr.com/photos/mptre/5152486610/"><img style="margin: 0px 0px 0px 5px; display: inline; float: right" align="right" src="http://farm2.static.flickr.com/1399/5152486610_24681b6e36_m.jpg" /></a>Often server applications need to upload or download files using FTP.&#160; But in this age of increasing security awareness vendors are now asking this be done using SFTP (Secure FTP).</p>
<p>Fortunately this is not difficult using the <a title="JSch - Java Secure Channel" href="http://www.jcraft.com/jsch/">JSch (Java Secure Channel) library</a>.&#160; The downloadable JSch archive includes numerous examples.&#160; I used the <tt>Sftp.java</tt> to implement SFTP for my server application.</p>
<p>Starting a connection to an SFTP server using JSch is somewhat simple.</p>
<pre>JSch jsch = new JSch();

// start session
session = jsch.getSession(username, host);

// specify our own user info to accept secure connection to FTP server
UserInfo ui = new MyUserInfo(host);
session.setUserInfo(ui);

// set password
session.setPassword(password);

// connect
session.connect();

// get SFTP channel
Channel channel = session.openChannel(&quot;sftp&quot;);
channel.connect();
schannel = (ChannelSftp) channel;</pre>
<p>The trick is getting past confirmation of the authenticity of the host. I do this my creating my own <tt>UserInfo</tt> implementation, <tt>MyUserInfo</tt>, which knows about the host I am connecting to. The only method I implement is the <tt>promptYesNo</tt> method which simply checks if the message is asking about the host I want to connect to. </p>
<pre>protected MyUserInfo(final String pKnownHost) {
    this.mKnownHost = pKnownHost;
}

@Override
public boolean promptYesNo(final String pMessage) {
    // message looks like this &quot;The authenticity of host 'foo.com' can't be established...&quot;
    final int start = pMessage.indexOf(&quot;'&quot;) + 1;
    final int end = pMessage.indexOf(&quot;'&quot;, start);
    final String host = pMessage.substring(start, end);

    // is the host a known host?
    return this.mKnownHost.equals(host);
}</pre>
<p>Now uploading is trivial.</p>
<pre>schannel.put(src, dest);</pre>
<p>For further reading please see <a title="ftp - Java: What is the best way to SFTP a file from a server - Stack Overflow" href="http://stackoverflow.com/questions/14617/java-what-is-the-best-way-to-sftp-a-file-from-a-server">Java: What is the best way to SFTP a file from a server</a>.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbetweengo.com%2F2011%2F02%2F21%2Fprogramming-secure-ftp-in-java%2F&amp;title=Programming%20Secure%20FTP%20in%20Java" 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/2005/08/12/acc-not-connecting/' rel='bookmark' title='ACC not connecting'>ACC not connecting</a></li>
<li><a href='http://betweengo.com/2008/09/01/java-method-with-generic-return-type/' rel='bookmark' title='Java Method with Generic Return Type'>Java Method with Generic Return Type</a></li>
<li><a href='http://betweengo.com/2008/04/18/oracle-tns-listener-service-not-starting/' rel='bookmark' title='Oracle TNS Listener service not starting'>Oracle TNS Listener service not starting</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://betweengo.com/2011/02/21/programming-secure-ftp-in-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Testing Which Page Loaded your JSP Page Fragment</title>
		<link>http://betweengo.com/2010/02/01/testing-which-page-loaded-your-jsp-page-fragment/</link>
		<comments>http://betweengo.com/2010/02/01/testing-which-page-loaded-your-jsp-page-fragment/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 16:49:00 +0000</pubDate>
		<dc:creator>Frank Kim</dc:creator>
				<category><![CDATA[JSTL]]></category>

		<guid isPermaLink="false">http://betweengo.com/2010/02/01/testing-which-page-loaded-your-jsp-page-fragment/</guid>
		<description><![CDATA[Zen Water by darkpatator Sometimes you want to check in your JSP page fragment which page loaded it.&#160; Fortunately this is simple with JSTL. &#60;c:if test=&#34;${fn:indexOf(pageContext.request.requestURI,'foo.jsp') != -1}&#34;&#62; The request URI ${pageContext.request.requestURI} contains foo.jsp. &#60;/c:if&#62; Simple but something I always forget how to do. Related posts: Get JSTL Vars from PageContext JSTL for current URI [...]
Related posts:<ol>
<li><a href='http://betweengo.com/2009/05/04/get-jstl-vars-from-pagecontext/' rel='bookmark' title='Get JSTL Vars from PageContext'>Get JSTL Vars from PageContext</a></li>
<li><a href='http://betweengo.com/2008/05/27/jstl-for-current-uri/' rel='bookmark' title='JSTL for current URI'>JSTL for current URI</a></li>
<li><a href='http://betweengo.com/2008/06/10/jsp-redirect-to-another-page/' rel='bookmark' title='JSP redirect to another page'>JSP redirect to another page</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/darkpatator/395226087/"><img style="display: block; float: none; margin-left: auto; margin-right: auto" title="Zen Water on Flickr" alt="Zen Water on Flickr" src="http://farm1.static.flickr.com/188/395226087_9002872142.jpg" /></a></p>
<p align="center"><a title="Zen Water on Flickr" href="http://www.flickr.com/photos/darkpatator/395226087/">Zen Water</a> by <a title="Flckr: darkpatator&#39;s Photostream" href="http://www.flickr.com/photos/darkpatator/">darkpatator</a></p>
<p>Sometimes you want to check in your JSP page fragment which page loaded it.&#160; Fortunately this is simple with JSTL.</p>
<pre>&lt;c:if test=&quot;${fn:indexOf(pageContext.request.requestURI,'foo.jsp') != -1}&quot;&gt;
  The request URI ${pageContext.request.requestURI} contains foo.jsp.
&lt;/c:if&gt;</pre>
<p>Simple but something I always forget how to do. <img src='http://betweengo.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbetweengo.com%2F2010%2F02%2F01%2Ftesting-which-page-loaded-your-jsp-page-fragment%2F&amp;title=Testing%20Which%20Page%20Loaded%20your%20JSP%20Page%20Fragment" id="wpa2a_4"><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/2009/05/04/get-jstl-vars-from-pagecontext/' rel='bookmark' title='Get JSTL Vars from PageContext'>Get JSTL Vars from PageContext</a></li>
<li><a href='http://betweengo.com/2008/05/27/jstl-for-current-uri/' rel='bookmark' title='JSTL for current URI'>JSTL for current URI</a></li>
<li><a href='http://betweengo.com/2008/06/10/jsp-redirect-to-another-page/' rel='bookmark' title='JSP redirect to another page'>JSP redirect to another page</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://betweengo.com/2010/02/01/testing-which-page-loaded-your-jsp-page-fragment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>URLEncoder.encode is Deprecated So What Do I Use for Encoding?</title>
		<link>http://betweengo.com/2009/10/31/urlencoder-encode-is-deprecated-so-what-do-i-use-for-encoding/</link>
		<comments>http://betweengo.com/2009/10/31/urlencoder-encode-is-deprecated-so-what-do-i-use-for-encoding/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 18:39:54 +0000</pubDate>
		<dc:creator>Frank Kim</dc:creator>
				<category><![CDATA[Java SE]]></category>
		<category><![CDATA[deprecated]]></category>

		<guid isPermaLink="false">http://betweengo.com/2009/10/31/urlencoder-encode-is-deprecated-so-what-do-i-use-for-encoding/</guid>
		<description><![CDATA[(Photo: The Surface by Daniel*1977) URLEncoder.encode(String url) is deprecated.&#160; Java wants you to use URLEncoder.encode(String url, String enc).&#160; But what do you put for the encoding parameter?&#160; I always forget which is the whole point of this post. URLEncoder.encode(url, &#34;UTF-8&#34;); Also on Windows if you want you can do: URLEncoder.encode(url, &#34;Cp1252&#34;); For further reading please [...]
Related posts:<ol>
<li><a href='http://betweengo.com/2009/03/17/encode-uri/' rel='bookmark' title='Encode URI'>Encode URI</a></li>
<li><a href='http://betweengo.com/2009/03/02/dynamically-generate-sitemapxml/' rel='bookmark' title='Dynamically generate sitemap.xml'>Dynamically generate sitemap.xml</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p style="text-align: center"><a href="http://www.flickr.com/photos/didmyself/3978834571/"><img title="The Surface on Flickr" alt="The Surface on Flickr" src="http://farm3.static.flickr.com/2476/3978834571_3e2528811f.jpg" /></a></p>
<p style="text-align: center">(Photo: <a title="The Surface on Flickr" href="http://www.flickr.com/photos/didmyself/3978834571/">The Surface</a> by <a title="Flickr: Daniel*1977&#39;s photostream" href="http://www.flickr.com/photos/didmyself/">Daniel*1977</a>)</p>
<p><a title="URLEncoder.encode(String url)" href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLEncoder.html#encode%28java.lang.String%29">URLEncoder.encode(String url)</a> is deprecated.&#160; Java wants you to use <a title="URLEncoder.encode(String url, String enc)" href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLEncoder.html#encode%28java.lang.String,%20java.lang.String%29">URLEncoder.encode(String url, String enc)</a>.&#160; But what do you put for the encoding parameter?&#160; I always forget which is the whole point of this post. <img src='http://betweengo.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<pre>URLEncoder.encode(url, &quot;UTF-8&quot;);</pre>
<p>Also on Windows if you want you can do:</p>
<pre>URLEncoder.encode(url, &quot;Cp1252&quot;);</pre>
<p>For further reading please see <a title="default encoding of a jvm" href="http://www.velocityreviews.com/forums/t124404-default-encoding-of-a-jvm.html">default encoding of a jvm</a>.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbetweengo.com%2F2009%2F10%2F31%2Furlencoder-encode-is-deprecated-so-what-do-i-use-for-encoding%2F&amp;title=URLEncoder.encode%20is%20Deprecated%20So%20What%20Do%20I%20Use%20for%20Encoding%3F" id="wpa2a_6"><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/2009/03/17/encode-uri/' rel='bookmark' title='Encode URI'>Encode URI</a></li>
<li><a href='http://betweengo.com/2009/03/02/dynamically-generate-sitemapxml/' rel='bookmark' title='Dynamically generate sitemap.xml'>Dynamically generate sitemap.xml</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://betweengo.com/2009/10/31/urlencoder-encode-is-deprecated-so-what-do-i-use-for-encoding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using ResourceBundle and MessageFormat for Error Messages</title>
		<link>http://betweengo.com/2009/09/07/using-resourcebundle-and-messageformat-for-error-messages/</link>
		<comments>http://betweengo.com/2009/09/07/using-resourcebundle-and-messageformat-for-error-messages/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 12:00:00 +0000</pubDate>
		<dc:creator>Frank Kim</dc:creator>
				<category><![CDATA[Java SE]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[MessageFormat]]></category>
		<category><![CDATA[ResourceBundle]]></category>

		<guid isPermaLink="false">http://betweengo.com/2009/09/04/using-resourcebundle-and-messageformat-for-error-messages/</guid>
		<description><![CDATA[When generating error messages, two Java utility classes, ResourceBundle and MessageFormat, are extremely practical and powerful.&#160; From the ResourceBundle JavaDoc: Resource bundles contain locale-specific objects. When your program needs a locale-specific resource, a String for example, your program can load it from the resource bundle that is appropriate for the current user&#8217;s locale. In this [...]
Related posts:<ol>
<li><a href='http://betweengo.com/2006/03/20/want-to-disable-windows-error-reporting/' rel='bookmark' title='HOWTO: Disable Windows Error Reporting?'>HOWTO: Disable Windows Error Reporting?</a></li>
<li><a href='http://betweengo.com/2008/05/05/color-code-outlook-messages/' rel='bookmark' title='Color Code Outlook Messages'>Color Code Outlook Messages</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>When generating error messages, two Java utility classes, <a title="ResourceBundle (Java Platform SE 6)" href="http://java.sun.com/javase/6/docs/api/java/util/ResourceBundle.html">ResourceBundle</a> and <a title="MessageFormat (Java Platform SE 6)" href="http://java.sun.com/javase/6/docs/api/java/text/MessageFormat.html">MessageFormat</a>, are extremely practical and powerful.&#160; From the ResourceBundle JavaDoc:</p>
<blockquote><p>Resource bundles contain locale-specific objects. When your program needs a locale-specific resource, a <a title="String (Java Platform SE 6)" href="http://java.sun.com/javase/6/docs/api/java/lang/String.html"><code>String</code></a> for example, your program can load it from the resource bundle that is appropriate for the current user&#8217;s locale. In this way, you can write program code that is largely independent of the user&#8217;s locale isolating most, if not all, of the locale-specific information in resource bundles. </p>
<p>This allows you to write programs that can: </p>
<ul>
<li>be easily localized, or translated, into different languages </li>
<li>handle multiple locales at once </li>
<li>be easily modified later to support even more locales </li>
</ul>
</blockquote>
<p>And from the MessageFormat JavaDoc:</p>
<blockquote><p><code>MessageFormat</code> provides a means to produce concatenated messages in a language-neutral way. Use this to construct messages displayed for end users. </p>
<p><code>MessageFormat</code> takes a set of objects, formats them, then inserts the formatted strings into the pattern at the appropriate places. </p>
</blockquote>
<p>This is an example of an error message resource bundle, <tt>ErrorMessagesResources.properties</tt>.</p>
<pre>userAlreadyExists=A user already exists with the name {0}.
passwordInvalid=Please enter a valid password.</pre>
<p>This is an example of how you would use this resource bundle.</p>
<pre>protected static final ResourceBundle resourceBundle =
    ResourceBundle.getBundle(&quot;com.betweengo.ErrorMessageResources&quot;);

public boolean handleLogin(DynamoHttpServletRequest pReq, DynamoHttpServletResponse pRes) {

  ...

  // user already exists
  String errMsg1 = resourceBundle.getString(&quot;userAlreadyExists&quot;);
  errMsg1 = MessageFormat.format(errMsg1, userName);

  ...

  // password invalid
  String errMsg2 = resourceBundle.getString(&quot;passwordInvalid&quot;);

  ...
}</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%2F09%2F07%2Fusing-resourcebundle-and-messageformat-for-error-messages%2F&amp;title=Using%20ResourceBundle%20and%20MessageFormat%20for%20Error%20Messages" id="wpa2a_8"><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/2006/03/20/want-to-disable-windows-error-reporting/' rel='bookmark' title='HOWTO: Disable Windows Error Reporting?'>HOWTO: Disable Windows Error Reporting?</a></li>
<li><a href='http://betweengo.com/2008/05/05/color-code-outlook-messages/' rel='bookmark' title='Color Code Outlook Messages'>Color Code Outlook Messages</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://betweengo.com/2009/09/07/using-resourcebundle-and-messageformat-for-error-messages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enums in Java</title>
		<link>http://betweengo.com/2009/09/02/enums-in-java/</link>
		<comments>http://betweengo.com/2009/09/02/enums-in-java/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 17:00:00 +0000</pubDate>
		<dc:creator>Frank Kim</dc:creator>
				<category><![CDATA[Java SE]]></category>
		<category><![CDATA[enums]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://betweengo.com/2009/09/01/enums-in-java/</guid>
		<description><![CDATA[(Photo: Slide-together : now with cards by fdecomite) Enums are highly useful data types introduced in Java SE 5.0.  Though I love using them I often forget the exact syntax so this post is to remind me later how to use it. public enum Example { FOO,BAR } // create one using its name Example [...]
Related posts:<ol>
<li><a href='http://betweengo.com/2008/06/12/covariant-return-types/' rel='bookmark' title='Covariant Return Types in Java'>Covariant Return Types in Java</a></li>
<li><a href='http://betweengo.com/2008/03/12/computing-basics-interview-questions/' rel='bookmark' title='Computing Basics Interview Questions'>Computing Basics Interview Questions</a></li>
<li><a href='http://betweengo.com/2007/03/28/printing-out-an-array/' rel='bookmark' title='Printing out an array'>Printing out an array</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p style="text-align: center"><a href="http://www.flickr.com/photos/fdecomite/3611388781/"><img title="Slide-together : now with cards on Flickr" src="http://farm4.static.flickr.com/3303/3611388781_0110324b5f.jpg" alt="Slide-together : now with cards on Flickr" /></a><br />
(Photo: <a title="Slide-together : now with cards on Flickr" href="http://www.flickr.com/photos/fdecomite/3611388781/">Slide-together : now with cards</a> by <a title="Flickr: fdecomite's Photostream" href="http://www.flickr.com/photos/fdecomite/">fdecomite</a>)</p>
<p><a title="Enum (Java 2 SE Platform 5.0)" href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Enum.html">Enums</a> are highly useful data types introduced in <a title="J2SE 5.0" href="http://java.sun.com/j2se/1.5.0/">Java SE 5.0</a>.  Though I love using them I often forget the exact syntax so this post is to remind me later how to use it.</p>
<pre>public enum Example {
  FOO,BAR
}

// create one using its name
Example myExample = Example.valueOf(“bar”.toUpperCase());

// if statement
if (myExample == Example.FOO) System.out.println(“FOO!”);

// switch statement
switch (myExample) {
  case FOO: System.out.println(“FOO!”);
  case BAR: System.out.println(“BAR!”);
}

// output as String using name
System.out.println(myExample.name());
</pre>
<p>For further reading please see Java’s <a title="Enums" href="http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html">Enums guide</a> and <a title="Enum Types (The Java™ Tutorials &gt; Learning the Java Language &gt; Classes and Objects)" href="http://java.sun.com/docs/books/tutorial/java/javaOO/enum.html">Enum Types (The Java™ Tutorials &gt; Learning the Java Language &gt; Classes and Objects)</a>.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbetweengo.com%2F2009%2F09%2F02%2Fenums-in-java%2F&amp;title=Enums%20in%20Java" id="wpa2a_10"><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/06/12/covariant-return-types/' rel='bookmark' title='Covariant Return Types in Java'>Covariant Return Types in Java</a></li>
<li><a href='http://betweengo.com/2008/03/12/computing-basics-interview-questions/' rel='bookmark' title='Computing Basics Interview Questions'>Computing Basics Interview Questions</a></li>
<li><a href='http://betweengo.com/2007/03/28/printing-out-an-array/' rel='bookmark' title='Printing out an array'>Printing out an array</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://betweengo.com/2009/09/02/enums-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit Test for Threaded Logging</title>
		<link>http://betweengo.com/2009/05/04/unit-test-for-threaded-logging/</link>
		<comments>http://betweengo.com/2009/05/04/unit-test-for-threaded-logging/#comments</comments>
		<pubDate>Mon, 04 May 2009 17:18:45 +0000</pubDate>
		<dc:creator>Frank Kim</dc:creator>
				<category><![CDATA[Java SE]]></category>
		<category><![CDATA[Logging]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://betweengo.com/?p=709</guid>
		<description><![CDATA[Brian Ploetz sent me this great unit test for threaded logging.  In it we are trying to find if a deadlock occurs. import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; import java.lang.management.ThreadMXBean; import junit.framework.TestCase; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.log4j.Appender; import org.apache.log4j.Logger; /** * Unit test for the ThrottlingFilter in a multi-threaded environment */ public class ThrottlingFilterThreadUTest extends TestCase [...]
Related posts:<ol>
<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>
<li><a href='http://betweengo.com/2008/05/27/log4j-levels/' rel='bookmark' title='Log4j levels'>Log4j levels</a></li>
<li><a href='http://betweengo.com/2007/02/07/accessing-javabeans-getters-and-setters/' rel='bookmark' title='Accessing JavaBean&#8217;s Getters and Setters'>Accessing JavaBean&#8217;s Getters and Setters</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a title="Brian Ploetz" href="http://www.linkedin.com/in/bploetz">Brian Ploetz</a> sent me this great unit test for threaded logging.  In it we are trying to find if a deadlock occurs.</p>
<pre>import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

import junit.framework.TestCase;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Appender;
import org.apache.log4j.Logger;

/**
 * Unit test for the ThrottlingFilter in a multi-threaded environment
 */
public class ThrottlingFilterThreadUTest extends TestCase {

  private static final Log logger = LogFactory.getLog(ThrottlingFilterThreadUTest.class);

  private static ThreadMXBean threadMXBean;

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    threadMXBean = ManagementFactory.getThreadMXBean();
    logger.info("Thread contention monitoring supported: "
        + threadMXBean.isThreadContentionMonitoringSupported());
    logger.info("Thread contention monitoring enabled: "
        + threadMXBean.isThreadContentionMonitoringEnabled());
    threadMXBean.setThreadContentionMonitoringEnabled(true);
    logger.info("Thread contention monitoring enabled: "
        + threadMXBean.isThreadContentionMonitoringEnabled());
  }

  /**
   * Tests multiple threads using the same filter instance at the same time
   */
  public void testThreads() {
    Logger rootLogger = Logger.getRootLogger();
    assertNotNull(rootLogger);
    Appender fileAppender = rootLogger.getAppender("FILE");
    assertNotNull(fileAppender);
    ThrottlingFilter throttlingFilter = (ThrottlingFilter) fileAppender.getFilter();
    assertNotNull(throttlingFilter);

    ThreadGroup infoThreadGroup = new ThreadGroup("info-group");
    ThreadGroup errorThreadGroup = new ThreadGroup("error-group");
    Thread errorThread1 = new ErrorThread(errorThreadGroup, "error-thread-1");
    Thread infoThread1 = new InfoThread(infoThreadGroup, "info-thread-1");
    Thread errorThread2 = new ErrorThread(errorThreadGroup, "error-thread-2");
    Thread infoThread2 = new InfoThread(infoThreadGroup, "info-thread-2");
    infoThread1.start();
    errorThread1.start();
    errorThread2.start();
    infoThread2.start();

    while (true) {
      ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds());
      for (int i = 0; i &lt; threadInfos.length; i++) {
        ThreadInfo threadInfo = threadInfos[i];
        if (threadInfo != null &amp;&amp; threadInfo.getThreadState() == Thread.State.BLOCKED) {
          System.out.println("Thread '" + threadInfo.getThreadName()
              + "' is blocked on the monitor lock '" + threadInfo.getLockName()
              + "' held by thread '" + threadInfo.getLockOwnerName() + "'");
        }
      }

      if (!infoThread1.isAlive() &amp;&amp; !errorThread1.isAlive() &amp;&amp; !infoThread2.isAlive()
          &amp;&amp; !errorThread2.isAlive())
        break;
    }
  }

  public static class ErrorThread extends Thread {

    private static final Log logger = LogFactory.getLog(ErrorThread.class);

    public ErrorThread(ThreadGroup tg, String name) {
      super(tg, name);
    }

    public void run() {
      for (int i = 0; i &lt; 10; i++) {
        try {
          test(0);
        } catch (Exception e) {
          long start = System.currentTimeMillis();
          logger.error("Error!", e);
          long end = System.currentTimeMillis();
          System.out.println("Took " + (end-start) + "ms to log error");
        }
      }
    }

    // simulate large stack traces
    private void test(int i) {
      if (i &gt;= 500)
        throw new RuntimeException("D'OH!");
      test(i+1);
    }
  }

  public static class InfoThread extends Thread {

    private static final Log logger = LogFactory.getLog(InfoThread.class);

    public InfoThread(ThreadGroup tg, String name) {
      super(tg, name);
    }

    public void run() {
      for (int i = 0; i &lt; 100; i++) {
        logger.info("Hi!");
      }
    }
  }
}</pre>
<p>The log4j.xml test file.</p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"&gt;

&lt;log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
    debug="false"&gt;

    &lt;!-- ================================= --&gt;
    &lt;!--           Appenders               --&gt;
    &lt;!-- ================================= --&gt;

    &lt;!-- A time/date based rolling file appender --&gt;
    &lt;appender name="FILE"
        class="org.apache.log4j.DailyRollingFileAppender"&gt;
        &lt;param name="File" value="server.log" /&gt;
        &lt;param name="Append" value="true" /&gt;

        &lt;!-- Rollover at midnight each day --&gt;
        &lt;param name="DatePattern" value="'.'yyyy-MM-dd" /&gt;

        &lt;layout class="org.apache.log4j.PatternLayout"&gt;
            &lt;!-- The default pattern: Date Priority [Category] Message\n --&gt;
            &lt;param name="ConversionPattern" value="%d %-5p [%c] %m%n" /&gt;
        &lt;/layout&gt;

        &lt;filter class="com.betweengo.log4j.ThrottlingFilter"&gt;
          &lt;param name="maxCountSameMessage" value="100"/&gt;
          &lt;param name="maxCountSavedMessages" value="100"/&gt;
          &lt;param name="waitInterval" value="60"/&gt;
        &lt;/filter&gt;
    &lt;/appender&gt;

    &lt;!-- ======================= --&gt;
    &lt;!-- Setup the Root category --&gt;
    &lt;!-- ======================= --&gt;

    &lt;root&gt;
        &lt;level value="INFO" /&gt;
        &lt;appender-ref ref="FILE" /&gt;
    &lt;/root&gt;

&lt;/log4j:configuration&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%2F05%2F04%2Funit-test-for-threaded-logging%2F&amp;title=Unit%20Test%20for%20Threaded%20Logging" id="wpa2a_12"><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/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>
<li><a href='http://betweengo.com/2008/05/27/log4j-levels/' rel='bookmark' title='Log4j levels'>Log4j levels</a></li>
<li><a href='http://betweengo.com/2007/02/07/accessing-javabeans-getters-and-setters/' rel='bookmark' title='Accessing JavaBean&#8217;s Getters and Setters'>Accessing JavaBean&#8217;s Getters and Setters</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://betweengo.com/2009/05/04/unit-test-for-threaded-logging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get JSTL Vars from PageContext</title>
		<link>http://betweengo.com/2009/05/04/get-jstl-vars-from-pagecontext/</link>
		<comments>http://betweengo.com/2009/05/04/get-jstl-vars-from-pagecontext/#comments</comments>
		<pubDate>Mon, 04 May 2009 15:02:17 +0000</pubDate>
		<dc:creator>Frank Kim</dc:creator>
				<category><![CDATA[JSTL]]></category>
		<category><![CDATA[ATG]]></category>
		<category><![CDATA[JSP]]></category>

		<guid isPermaLink="false">http://betweengo.com/?p=697</guid>
		<description><![CDATA[JSTL sets its vars in the pageContext.&#160; For example: pageContext.setAttribute(&#34;foo&#34;, bar); Therefore to get a JSTL variable use the pageContext within a tag or a JSP page.&#160; For example: // get item from pageContext and put in request atg.servlet.DynamoHttpServletRequest drequest = atg.servlet.ServletUtil.getDynamoRequest(request); drequest.setParameter(&#34;foo&#34;, pageContext.getAttribute(&#34;foo&#34;)); Note that getAttribute assumes the variable is in the page scope.&#160; [...]
Related posts:<ol>
<li><a href='http://betweengo.com/2008/05/27/jstl-for-current-uri/' rel='bookmark' title='JSTL for current URI'>JSTL for current URI</a></li>
<li><a href='http://betweengo.com/2008/05/09/accessing-repositoryitems-with-jstl/' rel='bookmark' title='Accessing RepositoryItems with JSTL'>Accessing RepositoryItems with JSTL</a></li>
<li><a href='http://betweengo.com/2005/08/30/jsp-dynamo-request-retrieval/' rel='bookmark' title='JSP Dynamo Request Retrieval'>JSP Dynamo Request Retrieval</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>JSTL sets its vars in the pageContext.&#160; For example:    </p>
<pre>pageContext.setAttribute(&quot;foo&quot;, bar);</pre>
<p>
  <br />Therefore to get a JSTL variable use the pageContext within a tag or a JSP page.&#160; For example: </p>
<p></p>
<pre>// get item from pageContext and put in request
atg.servlet.DynamoHttpServletRequest drequest = atg.servlet.ServletUtil.getDynamoRequest(request);
drequest.setParameter(&quot;foo&quot;, pageContext.getAttribute(&quot;foo&quot;));</pre>
<p>
  <br />Note that <tt>getAttribute</tt> assumes the variable is in the page scope.&#160; If you want to get a variable from for example the request scope you would do this.</p>
<pre>pageContext.getAttribute(&quot;foo&quot;, javax.servlet.PageContext.REQUEST_SCOPE);</pre>
<p>
  <br />For further reading please see <a title="PageContext (Jave EE 5 SDK)" href="http://download.oracle.com/javaee/5/api/javax/servlet/jsp/PageContext.html">PageContext</a>.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbetweengo.com%2F2009%2F05%2F04%2Fget-jstl-vars-from-pagecontext%2F&amp;title=Get%20JSTL%20Vars%20from%20PageContext" id="wpa2a_14"><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/05/27/jstl-for-current-uri/' rel='bookmark' title='JSTL for current URI'>JSTL for current URI</a></li>
<li><a href='http://betweengo.com/2008/05/09/accessing-repositoryitems-with-jstl/' rel='bookmark' title='Accessing RepositoryItems with JSTL'>Accessing RepositoryItems with JSTL</a></li>
<li><a href='http://betweengo.com/2005/08/30/jsp-dynamo-request-retrieval/' rel='bookmark' title='JSP Dynamo Request Retrieval'>JSP Dynamo Request Retrieval</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://betweengo.com/2009/05/04/get-jstl-vars-from-pagecontext/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting the request parameter</title>
		<link>http://betweengo.com/2009/04/10/getting-the-request-parameter/</link>
		<comments>http://betweengo.com/2009/04/10/getting-the-request-parameter/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 18:14:09 +0000</pubDate>
		<dc:creator>Frank Kim</dc:creator>
				<category><![CDATA[JSTL]]></category>
		<category><![CDATA[Page Development]]></category>
		<category><![CDATA[dsp]]></category>
		<category><![CDATA[JSP]]></category>

		<guid isPermaLink="false">http://betweengo.com/?p=687</guid>
		<description><![CDATA[I always forget how to do this so I thought I should write it down. In JSP: &#60;%=request.getParameter("foo")%&#62; &#60;img src="&#60;%=request.getParameter("foo")%&#62;"&#62; In JSTL: &#60;c:out value="${param.foo}"/&#62; In DSP: &#60;dspel:valueof param="foo"/&#62; Related posts: Comparison of DSP and DSPEL Accessing RepositoryItems with JSTL Display formatted HTML text
Related posts:<ol>
<li><a href='http://betweengo.com/2008/04/29/comparison-of-dsp-and-dspel/' rel='bookmark' title='Comparison of DSP and DSPEL'>Comparison of DSP and DSPEL</a></li>
<li><a href='http://betweengo.com/2008/05/09/accessing-repositoryitems-with-jstl/' rel='bookmark' title='Accessing RepositoryItems with JSTL'>Accessing RepositoryItems with JSTL</a></li>
<li><a href='http://betweengo.com/2008/08/12/display-formatted-html/' rel='bookmark' title='Display formatted HTML text'>Display formatted HTML text</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I always forget how to do this so I thought I should write it down.</p>
<p>In JSP:</p>
<pre>&lt;%=request.getParameter("foo")%&gt;
&lt;img src="&lt;%=request.getParameter("foo")%&gt;"&gt;</pre>
<p>In JSTL:</p>
<pre>&lt;c:out value="${param.foo}"/&gt;</pre>
<p>In DSP:</p>
<pre>&lt;dspel:valueof param="foo"/&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%2F04%2F10%2Fgetting-the-request-parameter%2F&amp;title=Getting%20the%20request%20parameter" id="wpa2a_16"><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/04/29/comparison-of-dsp-and-dspel/' rel='bookmark' title='Comparison of DSP and DSPEL'>Comparison of DSP and DSPEL</a></li>
<li><a href='http://betweengo.com/2008/05/09/accessing-repositoryitems-with-jstl/' rel='bookmark' title='Accessing RepositoryItems with JSTL'>Accessing RepositoryItems with JSTL</a></li>
<li><a href='http://betweengo.com/2008/08/12/display-formatted-html/' rel='bookmark' title='Display formatted HTML text'>Display formatted HTML text</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://betweengo.com/2009/04/10/getting-the-request-parameter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encode URI</title>
		<link>http://betweengo.com/2009/03/17/encode-uri/</link>
		<comments>http://betweengo.com/2009/03/17/encode-uri/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 21:14:56 +0000</pubDate>
		<dc:creator>Frank Kim</dc:creator>
				<category><![CDATA[Java SE]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://betweengo.com/?p=683</guid>
		<description><![CDATA[To encode an URI you can simply use Java&#8217;s URLEncoder&#8217;s encode method which has been available since JDK 1.4. String encodedUri; try { encodedUri = URLEncoder.encode(uri, "UTF-8"); } catch (UnsupportedEncodingException exc) { // this should never happen logger.warn("UTF-8 is not a supported encoding? Not encoding for now...", exc); encodedUri = uri; } Related posts: URLEncoder.encode [...]
Related posts:<ol>
<li><a href='http://betweengo.com/2009/10/31/urlencoder-encode-is-deprecated-so-what-do-i-use-for-encoding/' rel='bookmark' title='URLEncoder.encode is Deprecated So What Do I Use for Encoding?'>URLEncoder.encode is Deprecated So What Do I Use for Encoding?</a></li>
<li><a href='http://betweengo.com/2008/05/27/jstl-for-current-uri/' rel='bookmark' title='JSTL for current URI'>JSTL for current URI</a></li>
<li><a href='http://betweengo.com/2009/02/26/sleep/' rel='bookmark' title='Sleep'>Sleep</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>To encode an URI you can simply use Java&#8217;s <a title="URLEncoder (Java 2 Platform SE v1.4.2)" href="http://java.sun.com/j2se/1.4.2/docs/api/java/net/URLEncoder.html#encode(java.lang.String,%20java.lang.String)">URLEncoder&#8217;s encode</a> method which has been available since JDK 1.4.</p>
<pre>String encodedUri;
  try {
    encodedUri = URLEncoder.encode(uri, "UTF-8");
  }
  catch (UnsupportedEncodingException exc) {
    // this should never happen
    logger.warn("UTF-8 is not a supported encoding?  Not encoding for now...", exc);
    encodedUri = uri;
  }</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%2F17%2Fencode-uri%2F&amp;title=Encode%20URI" id="wpa2a_18"><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/2009/10/31/urlencoder-encode-is-deprecated-so-what-do-i-use-for-encoding/' rel='bookmark' title='URLEncoder.encode is Deprecated So What Do I Use for Encoding?'>URLEncoder.encode is Deprecated So What Do I Use for Encoding?</a></li>
<li><a href='http://betweengo.com/2008/05/27/jstl-for-current-uri/' rel='bookmark' title='JSTL for current URI'>JSTL for current URI</a></li>
<li><a href='http://betweengo.com/2009/02/26/sleep/' rel='bookmark' title='Sleep'>Sleep</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://betweengo.com/2009/03/17/encode-uri/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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_20"><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! -->
