开发者

how to hide the URLs access by the JSF navigation handler in 2.0

开发者 https://www.devze.com 2023-03-17 16:44 出处:网络
I have a web application which has开发者_JAVA百科 tomcat 6.0 and JSF 2.0 with richfaces 4.0.0 Final.

I have a web application which has开发者_JAVA百科 tomcat 6.0 and JSF 2.0 with richfaces 4.0.0 Final.

All my pages are with extension xhtml.

All my navigations in the faces-config.xml is also with .xhtml extensions.

Currently the browser shows the whole url with the .xhtml extension of the file that the FacesServlet navigates to.

I would like to show only the base URL like localhost:8080/appname for all navigations.

Is this possible?


Yes, it is possible if you put all static content such as images, stylesheets, javascripts and so on in a fixed common folder such as /static, /resources, /assets, etc and if you map the FacesServlet itself on an URL pattern of *.xhtml.

Then you can create a Filter which is mapped on an URL pattern of /* and transparently continues the request/response chain for all static content and dispatches the remnant to the FacesServlet.

String uri = ((HttpServletRequest) request).getRequestURI();

if (uri.startsWith("/static/")) {
    chain.doFilter(request, response); // Goes to default servlet.
} else {
    request.getRequestDispatcher(uri + ".xhtml").forward(request, response); // Goes to faces servlet.
}

This is not possible with a navigation handler as it has to be executed in the faces context which is only available if the faces servlet has run.

0

精彩评论

暂无评论...
验证码 换一张
取 消