Mask URL in JSF

孤者浪人 提交于 2019-12-04 16:25:09

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/*>
    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

Denis Rodin

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!