<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Bobobobo's Weblog &#187; Java</title>
	<atom:link href="http://bobobobo.wordpress.com/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://bobobobo.wordpress.com</link>
	<description>technology and the internets</description>
	<lastBuildDate>Mon, 30 Nov 2009 16:56:23 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='bobobobo.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/0e8d17c68f90a18a1e89a776717e00e2?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Bobobobo's Weblog &#187; Java</title>
		<link>http://bobobobo.wordpress.com</link>
	</image>
			<item>
		<title>How do I design a simple &#8220;front-controller&#8221;?</title>
		<link>http://bobobobo.wordpress.com/2008/05/04/how-do-i-design-a-simple-front-controller/</link>
		<comments>http://bobobobo.wordpress.com/2008/05/04/how-do-i-design-a-simple-front-controller/#comments</comments>
		<pubDate>Sun, 04 May 2008 15:05:50 +0000</pubDate>
		<dc:creator>bobobobo</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[internets]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://bobobobo.wordpress.com/?p=211</guid>
		<description><![CDATA[In any modern web app, you probably want to have really cool and simple URLs like how WordPress does for your permalinks.  E.g., the permalink for this posting is 
http://bobobobo.wordpress.com/2008/05/04/how-do-i-design-a-simple-front-controller/
MUCH better than the typical MSDN type urls:

http://msdn.microsoft.com/en-us/library/52cs05fz.aspx
http://msdn.microsoft.com/en-us/library/d06h2&#215;6e.aspx
http://msdn.microsoft.com/en-us/library/bb385954.aspx

Do you think when I complete this posting and publish it, WordPress will ACTUALLY PUT A FILE at [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bobobobo.wordpress.com&blog=2331964&post=211&subd=bobobobo&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In any modern web app, you probably want to have really cool and simple URLs like how WordPress does for your permalinks.  E.g., the permalink for this posting is </p>
<p><a href="http://bobobobo.wordpress.com/2008/05/04/how-do-i-design-a-simple-front-controller/">http://bobobobo.wordpress.com/2008/05/04/how-do-i-design-a-simple-front-controller/</a></p>
<p>MUCH better than the typical MSDN type urls:</p>
<blockquote>
<p>http://msdn.microsoft.com/en-us/library/52cs05fz.aspx</p>
<p>http://msdn.microsoft.com/en-us/library/d06h2&#215;6e.aspx</p>
<p>http://msdn.microsoft.com/en-us/library/bb385954.aspx</p>
</blockquote>
<p>Do you think when I complete this posting and publish it, WordPress will ACTUALLY PUT A FILE at <b>http://bobobobo.wordpress.com/2008/05/04/how-do-i-design-a-simple-front-controller/</b>?</p>
<p>NO you dummy!!</p>
<p>Anytime you see REALLY simple urls like http://www.website.com/PersonsUsername/ most likely what is happening there is the web application is using something called REQUEST MAPPING.  You do REQUEST MAPPING using what is called a FRONT CONTROLLER.</p>
<p>The FRONT CONTROLLER works to INTERPRET requests for specific URI&#8217;s AS requests to OTHER pages, engines, and so on.</p>
<p>Give <a href="http://cakephp.org/screencasts/view/3">this a watch</a>.</p>
<p>First, NOTICE how simple that uri is?  In case you didn&#8217;t follow the link through, its http://cakephp.org/screencasts/view/3.</p>
<p>So CakePHP a front controller to do &#8220;request mapping!&#8221;  WATCH THE VIDEO to get an idea, dude.</p>
<p>ANYWAY, how do you create a really simple front-controller and do request mapping from a Java servlet?</p>
<p>Just create a regular servlet, then make the web.xml entry for it something like this:</p>
<blockquote>
<pre>
&lt;servlet&gt;
  &lt;servlet-name&gt;member&lt;/servlet-name&gt;
  &lt;servlet-class&gt;member&lt;/servlet-class&gt;
&lt;/servlet&gt;

&lt;servlet-mapping&gt;
  &lt;servlet-name&gt;member&lt;/servlet-name&gt;
  &lt;url-pattern&gt;/member/*&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;
</pre>
</blockquote>
<p>NOTICE the /member/* for the &lt;url-pattern&gt;?  THAT means that ANY requests that come in with the pattern http://www.my.server.com/member/WHATEVER will AUTOMATICALLY be mapped down into the &#8220;member&#8221; servlet.</p>
<p>So the &#8220;member&#8221; servlet class might look something like this:</p>
<blockquote>
<pre>
public class member extends HttpServlet
{
  protected void doGet( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
  {
    String requestURI = request.getRequestURI();  // if the user hit
    // http://www.my.site.com/member/BOB then the REQUEST URI looks like
    // /member/BOB
    // All I'm going to do now is get everything after the last slash,
    // and that is what will tell me which member profile is desired:
    String desiredUserProfile = requestURI.substring( requestURI.lastIndexOf("/") + 1 );

    // work with desiredUserProfile to produce page output, whatever.
  }
}
</pre>
</blockquote>
<p>Get the idea?</p>
<p>See also:</p>
<p>Java:<br />
<a href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/FrontController.html">http://java.sun.com/blueprints/corej2eepatterns/Patterns/FrontController.html</a></p>
<p>PHP:<br />
<a href="http://www.phpwact.org/pattern/front_controller">http://www.phpwact.org/pattern/front_controller</a></p>
<p>Apache Server:</p>
<h1><a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html">mod_rewrite</a></h1>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/bobobobo.wordpress.com/211/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/bobobobo.wordpress.com/211/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bobobobo.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bobobobo.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bobobobo.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bobobobo.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bobobobo.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bobobobo.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bobobobo.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bobobobo.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bobobobo.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bobobobo.wordpress.com/211/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bobobobo.wordpress.com&blog=2331964&post=211&subd=bobobobo&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bobobobo.wordpress.com/2008/05/04/how-do-i-design-a-simple-front-controller/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a4ec51727310397c9e592dd84ae74dc2?s=96&#38;d=http%3A%2F%2Fa.wordpress.com%2Fi%2Fmu.gif" medium="image">
			<media:title type="html">bobobobo</media:title>
		</media:content>
	</item>
	</channel>
</rss>