怎么拦截 /app/**这样的请求

vue的前台: 需要返回到一个页面: 所以我需要: /app/**  都返回  /app/index.html

这个 /app/**  是多级的,

我应该怎么做。

评论区

hzh740053757

2020-01-12 16:25

写个Handler用正则表达式过滤

l745230

2020-01-13 09:03

public void configHandler(Handlers me) {
me.add(new WebHandler("^/sale", "/sale/index.html"));
}


public class WebHandler extends Handler {

private Pattern filterUrlRegxPattern;
private String indexPath;

public WebHandler(String filterUrlRegx, String indexPath) {
if (StrKit.isBlank(filterUrlRegx)) {
throw new IllegalArgumentException("The para filterUrlRegx can not be blank.");
}
filterUrlRegxPattern = Pattern.compile(filterUrlRegx);
this.indexPath = indexPath;
}

@Override
public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
if (filterUrlRegxPattern.matcher(target).find()
&& target.indexOf(".") == -1) {
HandlerKit.redirect(indexPath, request, response, isHandled);
} else {
next.handle(target, request, response, isHandled);
}
}

}

l745230

2020-01-13 09:05

也不知道哪个版本改了,如果不用HandlerKit.redirect的写法.跳到index.html全是403. 折腾了好久

tuxming

2020-01-13 09:12

谢谢

JFinal

2020-01-13 12:57

@l745230 感谢分享