How to avoid user access to .xhtml page in JSF?

后端 未结 5 1288
终归单人心
终归单人心 2020-12-06 02:05

I am new to JSF and writing first simply jsf web app.

URL with .jsf are mapping to .xhtml files in WebContent but why I can open .xhtml in web browser with all jsf t

5条回答
  •  既然无缘
    2020-12-06 02:08

    You can use a servlet filter

    @WebFilter(filterName = "XhtmlFilter", urlPatterns = { "*.xhtml" })
    public class XhtmlFilter implements Filter {
    
        @Override
        public void init(FilterConfig filterConfig) throws ServletException {
        }
    
        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
                throws IOException, ServletException {
            ((HttpServletResponse) response).sendError(404);
            chain.doFilter(request, response);
        }
    
        @Override
        public void destroy() {
        }
    }
    

提交回复
热议问题