In a JSF application, we have the directory hierarchy:
webapp
xhtml
login.xhtml
main.xhtml
search.xhtml
css
main.css
extra.css
js
jquery.js
etc. The servlet mapping is:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
This works fine, but the URLs of our web app look like this:
http://localhost/myapp/xhtml/login.xhtml
http://localhost/myapp/xhtml/search.xhtml
We would like to have simpler URLs by dropping the /xhtml part, i.e.
http://localhost/myapp/login.xhtml
I could not find any way to accomplish this. Is there some way to do this in the <servlet-mapping>? Do I need some additional framework?
You could do it with a
Filter. Either homegrown or a 3rd party one like URLRewriteFilter. Just map it on*.xhtmland then forward to/xhtml/*.Something like:
But simpler would be to just change the directory hierarchy to get rid of
/xhtmlsubfolder. Those CSS/JS (and image) files should preferably be placed in a/resourcessubfolder so that you can utilize the powers of<h:outputStylesheet>,<h:outputScript>and<h:graphicImage>in a proper way.See also: