[Logo] Mentawai Recipes
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
[Moderation Log] Moderation Log   [Register] Register / 
[Login] Login 
Using search-engine-friendly URLs  XML
Forum Index » Official Recipes
Author Message
saoj



Joined: 10/01/2008 08:20:15
Messages: 39
Offline

You can use the org.mentawai.core.PrettyURLController instead of the org.mentawai.core.Controller.

Instead of having:

http://www.mysite.com/MyContext/Topic.show.mtw?id=233&title=Welcome+to+Mentawai

http://www.mysite.com/MyContext/Topic.mtw?id=233&title=Welcome+to+Mentawai

You can have:

http://www.mysite.com/MyContext/mtw/Topic.show/233/Welcome-to-Mentawai

http://www.mysite.com/MyContext/mtw/Topic/233/Welcome-to-Mentawai

Note that you are losing the parameter names and that now you have mtw/ in front of every action URL.

The mtw/ is necessary so that you can correctly map the request to the controller in the web.xml file. Notice that we are using the PrettyURLController in the web.xml file:

OBS: If you don't want to have the mtw prefix you can map your actions some other way, like for example /Users/*.


Keep in mind that the parameters will be placed in the action input with the names "0", "1", "2", etc. So to get the parameters you should do:

Last but not least, you can use the PrettyURLParamFilter to give names to the parameters:

With the PrettyURLParamFilter, you can make any web application use the PrettyURLController without the need to change/migrate any action code.

And also feel free to use the old URL format (http://www.mysite.com/UserAction.show.mtw?id=23&category=34) with the new controller. It will just work! Just make sure you keep the *.mtw configured in the web.xml.

 
Forum Index » Official Recipes
Go to:   
Powered by JForum 2.1.8 © JForum Team