
Originally Posted by
lcmorley
I was originally using extensionless url's, but have now started using .htm. Is it possible to still use extensionless url's, if so, I would probably prefer that.
I was originally using .htm in my application (just because the Spring tutorial I followed did!) but I moved to extension-less URLs and am so glad I did. /clients/edit/34 looks much better than clientEdit.htm?clientId=34 in my opinion. It also fits in really nicely with Springs annotated controllers which can use URI templates which automatically extracts the 34 to a clientId variable for you!
The Spring PetClinic example (access using SVN at https://src.springframework.org/svn/...tclinic/trunk/) also uses extension-less URLs so I'd advise you to take a look at that but I'll try to give a very brief explanation here.
In web.xml you change the mapping from .htm to /app/*:
Code:
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
You also include a new filter that allows incoming URLs to be rewritten before they are processed by servlets:
Code:
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
N.B. I use Maven so I have included the following in pom.xml to get the UrlRewriteFilter in my project:
Code:
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>3.1.0</version>
<scope>runtime</scope>
</dependency>
The UrlRewriteFilter needs a configuration file to tell it how to manipulate the URLs:
urlrewrite.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<urlrewrite default-match-type="wildcard">
<rule>
<from>/static/**</from>
<to last="true">/static/$1</to>
</rule>
<rule>
<from>/</from>
<to last="true">/app/index</to>
</rule>
<rule>
<from>/**</from>
<to last="true">/app/$1</to>
</rule>
<outbound-rule>
<from>/app/**</from>
<to>/$1</to>
</outbound-rule>
</urlrewrite>
What this is basically saying is that incoming requests for /<something> will be routed to /app/<something>. The exception is for static resources which don't get routed under /app. So, static resources will be served by the container's default servlet which is very efficient.
As regards the AJAX stuff, that is my next obstacle, so may be posting questions about that next.
What I know about AJAX can be written on a postage stamp 
PUK