jfinal 拦截过滤.html或者.jsp请求

在config.java里面的configHandler方法里写一个Handler的匿名内部类, 重写handle方法, 在方法体里写要过滤的.jsp的请求

@Override
public void configHandler(Handlers me) {
    me.add(new ContextPathHandler("ctpath"));
    me.add(new Handler(){

        @Override
        public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
            //实现.jsp请求的判断
            int index = target.lastIndexOf(".jsp");
            if (index != -1)
                target = target.substring(0, index);
            nextHandler.handle(target, request, response, isHandled);
        }
    });
}

ps: 其实还可以弄点好玩的, 比如我把请求写成以.php结尾的, 就有点误导了, 吼吼 ...

你可能感兴趣的:(过滤,拦截,jFinal,.html,.jsp)