我在某个位置有一个过滤器(/ dir / store_image /*).
当我通过RequestDispatcher重定向到它时,它无效。
但它与response.sendRedirect一起工作正常。
对于requestDispatcher,输出是 - 请求的资源不可用。
示例代码 -
String path = req.getRequestURI() ;
path = path.substring(path.lastIndexOf("/")+1, path.length());
path = "../dir/store_image/" + path;
/* Not working
RequestDispatcher request_Dispatcher=request.getRequestDispatcher(path);
request_Dispatcher.forward(request,response);*/
//Working
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.sendRedirect(path);
过滤器映射 -
(来自StoreImageA,我转发到StoreImage)
<filter-mapping>
<filter-name>StoreImage</filter-name>
<url-pattern>/dir/store_image/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>StoreImageA</filter-name>
<url-pattern>/store_image/*</url-pattern>
</filter-mapping>