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 hide "Application/faces/"
Thanks
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:
- deploy your application to the context path
/
(how is application server-specific) - 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/*>
Order Allow,Deny
Allow From All
</Proxy>
ProxyPreserveHost On
ProxyPass / http://localhost:8080/WebApplication/
ProxyPassReverse / http://localhost:8080/WebApplication/
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.
PrettyFaces lets you rewrite your url. If you prefer something more lightweight, extend NavigationHandler and override handleNavigation, e.g. by calling context.getExternalContext().redirect()
Yep. We designed PrettyFaces exactly to handle this situation:
PrettyFaces – SEO, Dynamic Parameters, Bookmarks, and Navigation for JSF / JSF2
You can also change folder name from faces to jsp for example like this:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/jsp/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>jsp/index.jsp</welcome-file>
</welcome-file-list>
And then your url will looks like:
http://localhost/WebApplication/jsp/folder1/page.jsp
and if you deploy your application to the context path / of application server it will looks like:
http://localhost/jsp/folder1/page.jsp
it will be hard now to find out that you use JSF for lamers ;-) but a hacker can investigate it by pointing his browser to the url like this http://localhost/folder1/page.jsp
来源:https://stackoverflow.com/questions/490124/mask-url-in-jsf