InCombServlet.java 文件源码

java
阅读 28 收藏 0 点赞 0 评论 0

项目:InComb 作者:
/**
 * Rewrites all request without a file extension to <code>/index.html</code> and returns it
 * to the {@link DefaultServlet}. This is necessary because for URLs which will be handled
 * in Angular.js. It requires that Angular.js is loaded and that is by returning the content
 * of the index.html.
 */
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    final HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(request) {
        @Override
        public String getServletPath() {
            return "";
        }

        @Override
        public String getRequestURI() {
            return "";
        }

        @Override
        public String getPathInfo() {
            return super.getPathInfo().matches(".*\\/[^\\/]*\\.[^\\/]*$") ? super.getPathInfo() : "/index.html";
        }
    };

    final RequestDispatcher dispatcher = getServletContext().getNamedDispatcher("default");
    dispatcher.forward(wrapper, response);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号