Friday September 19, 2003
Vanity URLs in Struts I figured out a way to make your Struts' app have URLs like the following:
http://raibledesigns.com/weblog?method=edit http://raibledesigns.com/weblog.jsp?method=edit http://raibledesigns.com/weblog.html?method=edit http://raibledesigns.com/weblog.php?method=edit http://raibledesigns.com/weblog.asp?method=edit
Might be a nifty little trick to try. Pump out a version of Roller with this feature enabled and you could say you made a .NET version! ;-)
Here's how:
1. I created a RequestFilter that maps to /*
2. This filter checks to see if request.getServletPath() matches any of the
action paths in struts-config.xml. If so, it forwards to the action.
3. As an added feature, I added a set of allowed extensions to this
filter's init parameters. So far I have .jsp,.html,.asp,.cfm (using .jsp
ensures no one links to them directly, MVC enforced!) - so marketing can
choose what technology they want to convey ;-)
This seems to work great. For example, I have an "advancedSearch" action
defined as follows:
<action path="/advancedSearch"
type="org.apache.struts.actions.ForwardAction"
parameter=".advancedSearch"/>
(ForwardAction will eventually be replaced, if necessary, with a real
action). This allows all of the following URLs to work:
http://site.com/do/advancedSearch (works with Struts by default)
http://site.com/advancedSearch
http://site.com/advancedSearch.html + all other extensions listed.
More information (including source code) can be found on the struts-user mailing list.
Posted in Java
at Sep 19 2003, 06:23:24 PM MDT
2 Comments
Search This Site
Recent Entries
- Secure JSON Services with Play Scala and SecureSocial
- My What's New in Spring 3.1 Presentation
- Twitter's Open Source Summit: Bootstrap 2.0 Edition
- Refreshing AppFuse's UI with Twitter Bootstrap
- 2011 - A Year in Review
- Upgrading AppFuse to Spring Security 3.1 and Spring 3.1
- What have I been working on at Taleo?
- Our Engaging Trip to Paris and Antwerp
- My HTML5 with Play Scala, CoffeeScript and Jade Presentation from Devoxx 2011
- Deploying Java and Play Framework Apps to the Cloud with James Ward
Posted by Russ on September 21, 2003 at 11:13 AM MDT #
Posted by Matt Raible on September 21, 2003 at 10:27 PM MDT #