Skip navigation

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

MUCH better than the typical MSDN type urls:

Do you think when I complete this posting and publish it, WordPress will ACTUALLY PUT A FILE at

NO you dummy!!

Anytime you see REALLY simple urls like 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.

The FRONT CONTROLLER works to INTERPRET requests for specific URI’s AS requests to OTHER pages, engines, and so on.

Give this a watch.

First, NOTICE how simple that uri is? In case you didn’t follow the link through, its

So CakePHP a front controller to do “request mapping!” WATCH THE VIDEO to get an idea, dude.

ANYWAY, how do you create a really simple front-controller and do request mapping from a Java servlet?

Just create a regular servlet, then make the web.xml entry for it something like this:



NOTICE the /member/* for the <url-pattern>? THAT means that ANY requests that come in with the pattern will AUTOMATICALLY be mapped down into the “member” servlet.

So the “member” servlet class might look something like this:

public class member extends HttpServlet
  protected void doGet( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    String requestURI = request.getRequestURI();  // if the user hit
    // 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.

Get the idea?

See also:



Apache Server:



    • Anonymous
    • Posted April 23, 2009 at 3:45 pm
    • Permalink

    very good! but i extremely suggest if it was prepared in such a way that all lines and how to run things are explained…

    • nils
    • Posted March 24, 2010 at 11:13 pm
    • Permalink

    Agree with anon that the trick is what do you do once you get desiredUserProfile. It’s the key you use to look up in a HashMap, whose value is…etc. I think. That’s the bit worth describing.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: