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.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论