Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

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
Comments:

Hey Matt! Did you see my post not too long ago about a similar subject? I think your solution might be Tomcat specific as I was not able to convince Orion Server to map /* without screwing up the .jsp mapping. http://www.russellbeattie.com/notebook/1004094.html . If I tried to map everything (/*) when the request tried to process a .jsp, it would then loop back around to the controller and I'd get a stack overflow error. No amount of playing would fix this. In Tomcat, however, you can manually map *.jsp to Jasper before the /* and it'll respect the mapping. Is that what you're doing? Anyways, My solution involved RegEx which allowed a bit more flexibility in the URLs so you could do things like 20030921.html which would map to an arbitrary action. Not sure about its performance yet, but it works quite well on my desktop ;-) -Russ

Posted by Russ on September 21, 2003 at 05:13 PM MDT #

I don't believe my implementation is Tomcat specific. It basically will only forward to existing servlets (actions) that are defined in struts-config.xml.

Posted by Matt Raible on September 22, 2003 at 04:27 AM MDT #

Post a Comment:
  • HTML Syntax: Allowed