views:

1082

answers:

4

I have an enterprise application written in JAVA with JSF (using RichFaces 3.3). Currently my URL looks like this:

http://localhost/WebApplication/faces/folder1/page.jsp

Question is how do I mask my url to make it like this:

http://localhost/folder1/page.jps

Basically i want to hid "Application/faces/"

Thanks

+1  A: 

For rewriting URLs within your application you can use UrlRewrite. However, in this case it looks like you want to remove your web application's context path, in which case you have two options:

  1. deploy your application to the context path / (how is application server-specific)
  2. run Apache on port 80 and use mod_proxy to proxy certain URLs to your application server running on a different port, using configuration something like the following.

Apache config:

<Proxy http://localhost:8080/*&gt;
    Order Allow,Deny
    Allow From All
</Proxy>

ProxyPreserveHost On
ProxyPass / http://localhost:8080/WebApplication/
ProxyPassReverse / http://localhost:8080/WebApplication/
Peter Hilton
+1 for the UrlRewrite link. I've been looking for something like that!
Ed Brannin
You can also use PrettyFaces which is URL-rewriting specifically designed for JSF:http://ocpsoft.com/prettyfaces/
Lincoln
A: 

Note that the /faces/ is due to the mapping in web.xml. this is a standard mapping for JSF, however you could also use extension mapping - i.e. .faces at the end of the URL.

For example, in an application I have here this is in the web.xml file:

<servlet-mapping>
    <servlet-name>Persistent Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
</servlet-mapping>

This is using IceFaces, however it will be similar for you with RichFaces. Yours will probably look like this: <url-pattern>/faces/*</url-pattern>. If you change it to have *.faces as above, your end URL will look like this:

http://localhost/WebApplication/folder1/page.faces

If you use that in conjunction with the answer that Peter Hilton gave about deploying as a root web application, your end URL will look something like this:

http://localhost/folder1/page.faces

Which is almost exactly what you wanted.

Phill Sacre
+1  A: 

PrettyFaces lets you rewrite your url. If you prefer something more lightweight, extend NavigationHandler and override handleNavigation, e.g. by calling context.getExternalContext().redirect()

Yaniv
A: 

Yep. We designed PrettyFaces exactly to handle this situation:

PrettyFaces – SEO, Dynamic Parameters, Bookmarks, and Navigation for JSF / JSF2

Lincoln