【发布时间】:2017-08-16 09:47:26
【问题描述】:
我制作了一个过滤器,负责将.do 添加到请求中,并且是第一个声明的过滤器:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if(! (request instanceof HttpServletRequest)){
chain.doFilter(request, response );
}
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
String requestUrl = httpServletRequest.getServletPath();
if(!isBetaPathRequest(httpServletRequest) || StringUtils.contains(requestUrl,".")){
chain.doFilter(request, response );
return;
}
String newUrl = requestUrl;
int lastIndexOf = requestUrl.lastIndexOf("?");
if(lastIndexOf == -1){
if(requestUrl.charAt(requestUrl.length()-1) != '/'){
newUrl = newUrl.concat(".do");
}
}
else{
newUrl = requestUrl.substring(0, lastIndexOf-1) .concat(".do") .concat(requestUrl.substring(lastIndexOf));
}
final RequestDispatcher rq = getRequestDispatcher(request, newUrl);
rq.forward(request, response);
}
项目web.xml 文件中还声明了其他各种过滤器,我通过调试器通知它们没有运行。
一个重要过滤器的当前映射例如:
内容响应缓存过滤器 *。做
但最初的传入请求在通过BetaRewriteUrlFilter 之前不包括在 URl 中的.do。
当 RequestDispatcher.forward 被调用时,是否应用了过滤器,或者我们需要手动调用它们还是使用 302 重定向???
【问题讨论】:
标签: servlets web.xml servlet-filters